/
schema.sql
152 lines (122 loc) · 3.36 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- This script was generated by a beta version of the ERD tool in pgAdmin 4.
-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.
BEGIN;
CREATE TABLE public."Orders"
(
id integer NOT NULL,
product_id integer NOT NULL,
adres_id integer NOT NULL,
user_phone_number character varying(20) NOT NULL,
delivery_date date NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public."Products"
(
id integer NOT NULL,
name character varying(50) NOT NULL,
description text NOT NULL,
stock_code character varying(13) NOT NULL,
category_id integer NOT NULL,
inventory_id integer NOT NULL,
price double precision NOT NULL,
discount_id integer NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public."Users"
(
id integer NOT NULL,
user_name character varying(15) NOT NULL,
password character varying(25) NOT NULL,
first_name character varying(15) NOT NULL,
last_name character varying(15) NOT NULL,
phone_number character varying(20) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.discount
(
id integer NOT NULL,
product_id integer NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.inventory
(
id integer NOT NULL,
quantity character varying NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.order_destails
(
id integer NOT NULL,
product_id integer NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.product_category
(
id integer NOT NULL,
name character varying(23),
description character varying(250),
PRIMARY KEY (id)
);
CREATE TABLE public.user_address
(
id integer NOT NULL,
user_id integer NOT NULL,
adres_line1 character varying(120) NOT NULL,
adres_line2 character varying(50) NOT NULL,
zipcode "char" NOT NULL,
country name NOT NULL,
phone integer NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.user_payment
(
id integer NOT NULL,
user_id integer NOT NULL,
payment_type character varying(50) NOT NULL,
provider character varying(25) NOT NULL,
account_no character varying(25) NOT NULL,
vade date NOT NULL,
payment_detail character varying(240) NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE public."Orders"
ADD FOREIGN KEY (adres_id)
REFERENCES public.user_address (id)
NOT VALID;
ALTER TABLE public."Orders"
ADD FOREIGN KEY (product_id)
REFERENCES public."Products" (id)
NOT VALID;
ALTER TABLE public."Products"
ADD FOREIGN KEY (category_id)
REFERENCES public.product_category (id)
NOT VALID;
ALTER TABLE public."Products"
ADD FOREIGN KEY (category_id)
REFERENCES public.product_category (id)
NOT VALID;
ALTER TABLE public."Products"
ADD FOREIGN KEY (discount_id)
REFERENCES public.discount (id)
NOT VALID;
ALTER TABLE public."Products"
ADD FOREIGN KEY (inventory_id)
REFERENCES public.inventory (id)
NOT VALID;
ALTER TABLE public.order_destails
ADD FOREIGN KEY (product_id)
REFERENCES public."Products" (id)
NOT VALID;
ALTER TABLE public.user_address
ADD FOREIGN KEY (user_id)
REFERENCES public."Users" (id)
NOT VALID;
ALTER TABLE public.user_payment
ADD FOREIGN KEY (user_id)
REFERENCES public."Users" (id)
NOT VALID;
ALTER TABLE public.user_payment
ADD FOREIGN KEY (user_id)
REFERENCES public."Users" (id)
NOT VALID;
END;