-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_db_schema.sql
65 lines (58 loc) · 1.89 KB
/
example_db_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
/* DATABASE SCHEMA : example.db :: sqlite3 */
CREATE TABLE IF NOT EXISTS country (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS customer (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
country_id INTEGER NOT NULL,
FOREIGN KEY ( country_id )
REFERENCES country ( id )
ON DELETE CASCADE
ON UPDATE RESTRICT
);
CREATE TABLE IF NOT EXISTS merchant (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
country_id INTEGER NOT NULL,
FOREIGN KEY ( country_id )
REFERENCES country ( id )
ON DELETE CASCADE
ON UPDATE RESTRICT
);
CREATE TABLE IF NOT EXISTS product (
id INTEGER PRIMARY KEY AUTOINCREMENT,
merchant_id INTEGER NOT NULL,
name TEXT NOT NULL,
price REAL NOT NULL,
status TEXT NOT NULL,
FOREIGN KEY ( merchant_id )
REFERENCES merchant ( id )
ON DELETE CASCADE
ON UPDATE RESTRICT
);
CREATE TABLE IF NOT EXISTS customer_order (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_id INTEGER NOT NULL,
status TEXT NOT NULL,
FOREIGN KEY ( customer_id )
REFERENCES customer ( id )
ON DELETE CASCADE
ON UPDATE RESTRICT
);
CREATE TABLE IF NOT EXISTS order_item (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_order_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
quantity INTEGER NOT NULL,
FOREIGN KEY ( customer_order_id )
REFERENCES customer_order ( id )
ON DELETE CASCADE
ON UPDATE RESTRICT
FOREIGN KEY ( product_id )
REFERENCES product ( id )
ON DELETE CASCADE
ON UPDATE RESTRICT
);
/* END DATABASE SCHEMA : example.db :: sqlite3 */