-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sql
142 lines (126 loc) · 5.89 KB
/
install.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
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(191) NOT NULL DEFAULT '0',
`password` varchar(191) NOT NULL DEFAULT '0',
`email` varchar(512) NOT NULL DEFAULT '0',
`activationKey` varchar(8) DEFAULT NULL,
`userRights` enum('USER','ADMIN') DEFAULT 'USER',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`),
KEY `activationKey` (`username`,`activationKey`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `categories`;
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`label` varchar(200) NOT NULL DEFAULT '0',
`parentId` int(10) unsigned DEFAULT NULL,
`position` int(10) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `products`;
CREATE TABLE IF NOT EXISTS `products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(191) CHARACTER SET utf8 NOT NULL,
`description` text CHARACTER SET utf8 NOT NULL,
`price` int(11) NOT NULL DEFAULT 0,
`status` enum('DRAFT','LIVE') NOT NULL DEFAULT 'DRAFT',
`slug` varchar(140) NOT NULL DEFAULT '',
`category_id` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `slug` (`slug`),
KEY `FK_product_category` (`category_id`),
CONSTRAINT `FK_product_category` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `cart`;
CREATE TABLE IF NOT EXISTS `cart` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL DEFAULT 0,
`product_id` int(10) unsigned DEFAULT NULL,
`quantity` int(10) unsigned NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `product_id_user_id` (`product_id`,`user_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `FK_cart_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `delivery_adresses`;
CREATE TABLE IF NOT EXISTS `delivery_adresses` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) unsigned NOT NULL,
`recipient` text NOT NULL,
`city` text NOT NULL,
`street` text NOT NULL,
`streetNumber` varchar(50) NOT NULL,
`zipCode` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_user_delivery_addresses` (`user_id`),
CONSTRAINT `FK_user_delivery_addresses` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `orders`;
CREATE TABLE IF NOT EXISTS `orders` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`orderDate` date NOT NULL DEFAULT '0000-00-00',
`deliveryDate` date NOT NULL DEFAULT '0000-00-00',
`status` enum('new','canceled','payed','sent','delivered') NOT NULL DEFAULT 'new',
`userId` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `orderDate` (`orderDate`),
KEY `status` (`status`),
KEY `userId` (`userId`),
CONSTRAINT `FK_ORDER_TO_USER` FOREIGN KEY (`userId`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `order_adresses`;
CREATE TABLE IF NOT EXISTS `order_adresses` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`order_id` int(11) unsigned NOT NULL,
`recipient` mediumtext NOT NULL,
`city` text NOT NULL,
`street` text NOT NULL,
`streetNumber` varchar(50) NOT NULL,
`zipCode` varchar(50) NOT NULL,
`type` enum('both','delivery','invoice') DEFAULT 'both',
PRIMARY KEY (`id`),
KEY `FK_ORDER_ADRESS` (`order_id`),
KEY `type` (`type`),
CONSTRAINT `FK_ORDER_ADRESS` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `order_products`;
CREATE TABLE IF NOT EXISTS `order_products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL DEFAULT '',
`quantity` int(10) unsigned NOT NULL DEFAULT 0,
`price` int(10) unsigned NOT NULL DEFAULT 0,
`taxInPercent` int(10) unsigned NOT NULL DEFAULT 0,
`orderId` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `FK_ODERS_TO_ORDER_PRODUCTS` (`orderId`),
CONSTRAINT `FK_ODERS_TO_ORDER_PRODUCTS` FOREIGN KEY (`orderId`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `reviews` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`product_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`value` int(10) unsigned NOT NULL,
`title` varchar(50) NOT NULL DEFAULT '',
`text` text NOT NULL,
`created` datetime NOT NULL DEFAULT current_timestamp(),
`status` enum('PUBLIC','PRIVATE') NOT NULL DEFAULT 'PRIVATE',
PRIMARY KEY (`id`),
UNIQUE KEY `product_id_user_id` (`product_id`,`user_id`),
KEY `product_id_status` (`product_id`,`status`),
KEY `FK_USER_REVIEWS` (`user_id`),
CONSTRAINT `FK_PRODUCT_REVIEWS` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_USER_REVIEWS` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;