-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcatalog_database.sql
206 lines (166 loc) · 5.18 KB
/
catalog_database.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
-- phpMyAdmin SQL Dump
-- version 4.8.3
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Czas generowania: 13 Sie 2019, 13:42
-- Wersja serwera: 10.1.36-MariaDB
-- Wersja PHP: 7.2.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Baza danych: `catalog_database`
--
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `categories`
--
CREATE TABLE `categories` (
`cat_id` int(11) NOT NULL,
`cat_name` varchar(50) COLLATE utf8_polish_ci NOT NULL,
`cat_desc` text COLLATE utf8_polish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `clipboard`
--
CREATE TABLE `clipboard` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`prod_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `products`
--
CREATE TABLE `products` (
`prod_id` int(11) NOT NULL,
`prod_name` varchar(100) COLLATE utf8_polish_ci NOT NULL,
`prod_desc` text COLLATE utf8_polish_ci NOT NULL,
`prod_img` varchar(200) COLLATE utf8_polish_ci DEFAULT NULL,
`add_date` varchar(30) COLLATE utf8_polish_ci NOT NULL,
`category_id` int(11) DEFAULT NULL,
`prod_price` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `users`
--
CREATE TABLE `users` (
`user_id` int(11) NOT NULL,
`user_name` varchar(20) COLLATE utf8_polish_ci NOT NULL,
`user_email` varchar(40) COLLATE utf8_polish_ci NOT NULL,
`user_passwd` varchar(255) COLLATE utf8_polish_ci NOT NULL,
`type_id` int(11) NOT NULL,
`is_active` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
--
-- Zrzut danych tabeli `users`
--
INSERT INTO `users` (`user_id`, `user_name`, `user_email`, `user_passwd`, `type_id`, `is_active`) VALUES
(1, 'admin', 'admin@gmail.com', '$2y$10$WeKk9z7La0DY7X.P/c57c.t9BCm.9u9tbUP4jS6WiyGBcI.c3B7Oq', 1, 1);
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `user_types`
--
CREATE TABLE `user_types` (
`type_id` int(11) NOT NULL,
`type_name` varchar(20) COLLATE utf8_polish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
--
-- Zrzut danych tabeli `user_types`
--
INSERT INTO `user_types` (`type_id`, `type_name`) VALUES
(1, 'admin'),
(2, 'user');
--
-- Indeksy dla zrzutów tabel
--
--
-- Indeksy dla tabeli `categories`
--
ALTER TABLE `categories`
ADD PRIMARY KEY (`cat_id`);
--
-- Indeksy dla tabeli `clipboard`
--
ALTER TABLE `clipboard`
ADD PRIMARY KEY (`id`) USING BTREE,
ADD UNIQUE KEY `UNIQUE` (`user_id`,`prod_id`),
ADD KEY `FK_Clipboard_User` (`user_id`),
ADD KEY `FK_Clipboard_Product` (`prod_id`);
--
-- Indeksy dla tabeli `products`
--
ALTER TABLE `products`
ADD PRIMARY KEY (`prod_id`),
ADD KEY `FK_Product_Category` (`category_id`);
--
-- Indeksy dla tabeli `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`user_id`),
ADD KEY `FK_User_Type` (`type_id`);
--
-- Indeksy dla tabeli `user_types`
--
ALTER TABLE `user_types`
ADD PRIMARY KEY (`type_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT dla tabeli `categories`
--
ALTER TABLE `categories`
MODIFY `cat_id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT dla tabeli `clipboard`
--
ALTER TABLE `clipboard`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT dla tabeli `products`
--
ALTER TABLE `products`
MODIFY `prod_id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT dla tabeli `users`
--
ALTER TABLE `users`
MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT dla tabeli `user_types`
--
ALTER TABLE `user_types`
MODIFY `type_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- Ograniczenia dla zrzutów tabel
--
--
-- Ograniczenia dla tabeli `clipboard`
--
ALTER TABLE `clipboard`
ADD CONSTRAINT `FK_Clipboard_Product` FOREIGN KEY (`prod_id`) REFERENCES `products` (`prod_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `FK_Clipboard_User` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ograniczenia dla tabeli `products`
--
ALTER TABLE `products`
ADD CONSTRAINT `FK_Product_Category` FOREIGN KEY (`category_id`) REFERENCES `categories` (`cat_id`) ON DELETE SET NULL ON UPDATE CASCADE;
--
-- Ograniczenia dla tabeli `users`
--
ALTER TABLE `users`
ADD CONSTRAINT `FK_User_Type` FOREIGN KEY (`type_id`) REFERENCES `user_types` (`type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;