-
Notifications
You must be signed in to change notification settings - Fork 34
/
09-schema.sql
82 lines (67 loc) · 1.75 KB
/
09-schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
--
-- Databáze: `xname`
--
-- --------------------------------------------------------
--
-- Struktura tabulky `goods`
--
CREATE TABLE `goods` (
`id` int(10) UNSIGNED NOT NULL,
`name` varchar(255) DEFAULT NULL,
`description` text DEFAULT NULL,
`price` decimal(10,2) NOT NULL DEFAULT 0.00,
`last_updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`last_edit_starts_at` timestamp NULL DEFAULT NULL,
`last_edit_starts_by_user` int(10) UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Struktura tabulky `users`
--
CREATE TABLE `users` (
`id` int(10) UNSIGNED NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`role` set('user','admin') NOT NULL DEFAULT 'user'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Klíče pro exportované tabulky
--
--
-- Klíče pro tabulku `goods`
--
ALTER TABLE `goods`
ADD PRIMARY KEY (`id`),
ADD KEY `last_edit_starts_by_user` (`last_edit_starts_by_user`);
--
-- Klíče pro tabulku `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `email` (`email`);
--
-- AUTO_INCREMENT pro tabulky
--
--
-- AUTO_INCREMENT pro tabulku `goods`
--
ALTER TABLE `goods`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT pro tabulku `users`
--
ALTER TABLE `users`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- Omezení pro exportované tabulky
--
--
-- Omezení pro tabulku `goods`
--
ALTER TABLE `goods`
ADD CONSTRAINT `goods_ibfk_1` FOREIGN KEY (`last_edit_starts_by_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE;
COMMIT;