-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dikann.sql
98 lines (83 loc) · 2.33 KB
/
Dikann.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
CREATE TABLE "user" (
"id" bigint PRIMARY KEY,
"email" varchar,
"username" varchar,
"password" varchar,
"first_name" varchar,
"last_name" varchar,
"created_date" timestamp,
"modified_date" timestamp
);
CREATE TABLE "user_address" (
"id" bigint PRIMARY KEY,
"address_line1" varchar,
"address_line2" varchar,
"postal_code" varchar,
"city" varchar,
"country" varchar,
"phone" varchar,
"user_id" bigint
);
CREATE TABLE "product" (
"id" bigint PRIMARY KEY,
"name" varchar,
"desc" varchar,
"image_url" varchar,
"sku" varchar,
"price" decimal,
"quantity" bigint,
"created_date" timestamp,
"modified_date" timestamp,
"discount_id" bigint,
"category_id" bigint
);
CREATE TABLE "discount" (
"id" bigint PRIMARY KEY,
"name" varchar,
"desc" varchar,
"discount_percentage" decimal,
"active" boolean,
"created_date" timestamp,
"modified_date" timestamp
);
CREATE TABLE "category" (
"id" bigint PRIMARY KEY,
"name" varchar,
"desc" varchar,
"image_url" varchar,
"created_date" timestamp,
"modified_date" timestamp
);
CREATE TABLE "order" (
"id" bigint PRIMARY KEY,
"status" varchar,
"total_discount" decimal,
"created_date" timestamp,
"modified_date" timestamp,
"shopping_session_id" bigint,
"user_address_id" bigint
);
CREATE TABLE "shopping_session" (
"id" bigint PRIMARY KEY,
"user_id" bigint,
"total" decimal,
"valid" boolean,
"created_date" timestamp,
"modified_date" timestamp
);
CREATE TABLE "cart_item" (
"id" bigint PRIMARY KEY,
"shopping_session_id" bigint,
"product_id" bigint,
"quantity" bigint,
"created_date" timestamp,
"modified_date" timestamp
);
ALTER TABLE "user_address" ADD FOREIGN KEY ("user_id") REFERENCES "user" ("id");
ALTER TABLE "shopping_session" ADD FOREIGN KEY ("user_id") REFERENCES "user" ("id");
ALTER TABLE "discount" ADD FOREIGN KEY ("id") REFERENCES "product" ("discount_id");
ALTER TABLE "product" ADD FOREIGN KEY ("category_id") REFERENCES "category" ("id");
ALTER TABLE "order" ADD FOREIGN KEY ("user_address_id") REFERENCES "user_address" ("id");
ALTER TABLE "cart_item" ADD FOREIGN KEY ("shopping_session_id") REFERENCES "shopping_session" ("id");
ALTER TABLE "cart_item" ADD FOREIGN KEY ("product_id") REFERENCES "product" ("id");
ALTER TABLE "order" ADD FOREIGN KEY ("shopping_session_id") REFERENCES "shopping_session" ("id");