-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
99 lines (87 loc) · 2.5 KB
/
init.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
DROP DATABASE IF EXISTS ds_estore_db;
CREATE DATABASE ds_estore_db;
DROP USER IF EXISTS 'ds_estore_db'@'localhost';
CREATE USER 'ds_estore_db'@'localhost' IDENTIFIED BY 'ds_estore_db';
GRANT ALL ON ds_estore_db.* TO 'ds_estore_db'@'localhost';
USE ds_estore_db;
CREATE TABLE product (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
slug VARCHAR(128) NOT NULL,
shortDescription VARCHAR(512) NOT NULL,
description VARCHAR(2048) NOT NULL,
sku VARCHAR(128) NOT NULL,
price FLOAT NOT NULL,
onsale BOOLEAN NOT NULL,
onsalePrice FLOAT,
externalUrl VARCHAR(2048),
meta JSON,
unavailable BOOLEAN DEFAULT FALSE,
productImage VARCHAR(2048),
createdAt DATETIME DEFAULT NOW(),
modifiedAt DATETIME
);
CREATE TABLE category (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
slug VARCHAR(128) NOT NULL,
shortDescription VARCHAR(512) NOT NULL,
description VARCHAR(2048) NOT NULL,
meta JSON,
categoryImage VARCHAR(2048),
createdAt DATETIME DEFAULT NOW(),
modifiedAt DATETIME
);
CREATE TABLE tag (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
slug VARCHAR(128) NOT NULL,
meta JSON,
createdAt DATETIME DEFAULT NOW(),
modifiedAt DATETIME
);
CREATE TABLE `order` (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
address VARCHAR(128) NOT NULL,
state VARCHAR(128) NOT NULL,
country VARCHAR(128) NOT NULL,
town VARCHAR(128) NOT NULL,
phone VARCHAR(24) NOT NULL,
email VARCHAR(320) NOT NULL,
zipCode VARCHAR(24) NOT NULL,
note TEXT,
meta JSON,
closed DATETIME,
createdAt DATETIME DEFAULT NOW(),
modifiedAt DATETIME
);
CREATE TABLE parent_category_links (
id INT AUTO_INCREMENT PRIMARY KEY,
parentCategoryId INT,
childCategoryId INT,
FOREIGN KEY (parentCategoryId) REFERENCES category(id),
FOREIGN KEY (childCategoryId) REFERENCES category(id)
);
CREATE TABLE order_products_links (
id INT AUTO_INCREMENT PRIMARY KEY,
orderId INT,
productId INT,
amount INT,
FOREIGN KEY (orderId) REFERENCES `order`(id) ON DELETE CASCADE,
FOREIGN KEY (productId) REFERENCES `product`(id) ON DELETE CASCADE
);
CREATE TABLE product_category_links (
id INT AUTO_INCREMENT PRIMARY KEY,
categoryId INT,
productId INT,
FOREIGN KEY (categoryId) REFERENCES category(id),
FOREIGN KEY (productId) REFERENCES product(id)
);
CREATE TABLE product_tag_links (
id INT AUTO_INCREMENT PRIMARY KEY,
tagId INT,
productId INT,
FOREIGN KEY (tagId) REFERENCES tag(id),
FOREIGN KEY (productId) REFERENCES product(id)
);