-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShoppingCart_PostgreSQL-1726597235.sql
74 lines (61 loc) · 2.47 KB
/
ShoppingCart_PostgreSQL-1726597235.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
CREATE TABLE IF NOT EXISTS "User" (
"UserID" serial NOT NULL UNIQUE,
"FullName" varchar(255) NOT NULL,
"PhoneNumber" bigint NOT NULL,
"Email" varchar(255) NOT NULL,
"CardID" numeric(10,0) NOT NULL,
PRIMARY KEY ("UserID")
);
CREATE TABLE IF NOT EXISTS "Order" (
"OrderID" serial NOT NULL UNIQUE,
"UserID" bigint NOT NULL,
"OrderDate" timestamp with time zone NOT NULL,
"OrderStatus" varchar(255) NOT NULL,
"PaymentStatus" varchar(255) NOT NULL,
"ExpectedDeliveryDate" timestamp with time zone NOT NULL,
"DeliveryAddress" varchar(255) NOT NULL,
"PickupPointID" bigint NOT NULL,
"CourierServiceID" bigint NOT NULL,
PRIMARY KEY ("OrderID")
);
CREATE TABLE IF NOT EXISTS "Product" (
"ProductID" serial NOT NULL UNIQUE,
"ProductName" varchar(255) NOT NULL,
"Price" numeric(10,0) NOT NULL,
"StockQuantity" bigint NOT NULL,
"Description" varchar(255) NOT NULL,
PRIMARY KEY ("ProductID")
);
CREATE TABLE IF NOT EXISTS "OrderItem" (
"OrderItemID" serial NOT NULL UNIQUE,
"OrderID" bigint NOT NULL,
"ProductID" bigint NOT NULL,
"Quantity" bigint NOT NULL,
PRIMARY KEY ("OrderItemID")
);
CREATE TABLE IF NOT EXISTS "PickupPoint" (
"PickupPointID" serial NOT NULL UNIQUE,
"Address" varchar(255) NOT NULL,
PRIMARY KEY ("PickupPointID")
);
CREATE TABLE IF NOT EXISTS "CourierService" (
"CourierServiceID" serial NOT NULL UNIQUE,
"ServiceName" varchar(255) NOT NULL,
"DeliveryTimeEstimate" varchar(255) NOT NULL,
PRIMARY KEY ("CourierServiceID")
);
CREATE TABLE IF NOT EXISTS "TransactionLog" (
"LogID_" serial NOT NULL UNIQUE,
"UserID" bigint NOT NULL,
"OrderID" bigint NOT NULL,
"Action" varchar(255) NOT NULL,
"Timestamp" timestamp with time zone NOT NULL,
PRIMARY KEY ("LogID_")
);
ALTER TABLE "User" ADD CONSTRAINT "User_fk0" FOREIGN KEY ("UserID") REFERENCES "Order"("UserID");
ALTER TABLE "Order" ADD CONSTRAINT "Order_fk0" FOREIGN KEY ("OrderID") REFERENCES "OrderItem"("OrderID");
ALTER TABLE "Order" ADD CONSTRAINT "Order_fk7" FOREIGN KEY ("PickupPointID") REFERENCES "PickupPoint"("PickupPointID");
ALTER TABLE "Order" ADD CONSTRAINT "Order_fk8" FOREIGN KEY ("CourierServiceID") REFERENCES "CourierService"("CourierServiceID");
ALTER TABLE "Product" ADD CONSTRAINT "Product_fk0" FOREIGN KEY ("ProductID") REFERENCES "OrderItem"("ProductID");
ALTER TABLE "TransactionLog" ADD CONSTRAINT "TransactionLog_fk1" FOREIGN KEY ("UserID") REFERENCES "User"("UserID");
ALTER TABLE "TransactionLog" ADD CONSTRAINT "TransactionLog_fk2" FOREIGN KEY ("OrderID") REFERENCES "Order"("OrderID");