-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
104 lines (97 loc) · 3.44 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
CREATE TABLE categorie (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
category_name VARCHAR(255),
description VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at)
);
CREATE TABLE customer (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(50),
contact_name VARCHAR(30),
address TEXT,
city VARCHAR(255),
postal_code VARCHAR(16),
country VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at)
);
CREATE TABLE employee (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
last_name VARCHAR(30),
first_name VARCHAR(30),
birth_date VARCHAR(30),
photo VARCHAR(50),
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at)
);
CREATE TABLE shipper (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
shipper_name VARCHAR(50),
phone VARCHAR(15),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at)
);
CREATE TABLE supplier (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
supplier_name VARCHAR(50),
contact_name VARCHAR(50),
address TEXT,
city VARCHAR(30),
postal_code VARCHAR(16),
country VARCHAR(30),
phone VARCHAR(15),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at)
);
CREATE TABLE orders (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
customer_id INT(11),
employee_id INT(11),
shipper_id INT(11),
order_date VARCHAR(30),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at),
FOREIGN KEY (customer_id) REFERENCES customer(id),
FOREIGN KEY (employee_id) REFERENCES employee(id),
FOREIGN KEY (shipper_id) REFERENCES shipper(id)
);
CREATE TABLE product (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(50),
supplier_id INT(11),
category_id INT(11),
unit VARCHAR(30),
price FLOAT(10,2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at),
FOREIGN KEY (supplier_id) REFERENCES supplier(id),
FOREIGN KEY (category_id) REFERENCES categorie(id)
);
CREATE TABLE order_detail (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
order_id INT(11),
product_id INT(11),
quantity INT(11),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
INDEX idx_deleted_at (deleted_at),
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES product(id)
);