-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheme.sql
153 lines (134 loc) · 3.79 KB
/
scheme.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
153
drop table if exists bid cascade ;
drop table if exists category cascade ;
drop table if exists client cascade ;
drop table if exists client cascade ;
drop table if exists login_credentials cascade ;
drop table if exists password_reset cascade ;
drop table if exists product_favourites cascade ;
drop table if exists user_favourites cascade ;
drop table if exists product cascade ;
drop table if exists session cascade ;
create table category
(
id serial primary key,
name varchar(20) not null,
description varchar(250) not null
);
alter table category
owner to postgres;
create table client
(
id serial primary key,
name varchar(50) not null,
last_name varchar(50) not null,
address varchar(100) not null,
city varchar(100) not null,
birth_date date not null,
gender varchar(10) not null
);
alter table client
owner to postgres;
create table login_credentials
(
id serial primary key,
username varchar(20) not null,
password varchar(60) not null,
kind varchar(10) not null,
client_id integer
constraint user_fk
references client (id)
on delete cascade ,
constraint username_unique
unique (username)
);
alter table login_credentials
owner to postgres;
create table password_reset
(
login_id integer not null
constraint login_credentials_fk
references login_credentials(id)
on delete cascade ,
request_id varchar(20) not null,
primary key (login_id,request_id)
);
alter table password_reset
owner to postgres;
create table product
(
id serial primary key,
title varchar(50) not null,
description varchar(250) not null,
out_price double precision not null,
images varchar(100),
close_date date,
publish_date timestamp not null,
vendor_id integer not null
constraint vendor_fk
references client (id)
on delete cascade ,
category_id integer not null
constraint category_fk
references category (id)
on delete cascade
);
alter table product
owner to postgres;
create table user_favourites
(
category_id integer not null
constraint category_fk
references category (id)
on delete cascade ,
client_id integer not null
constraint user_fk
references client (id)
on delete cascade ,
primary key (category_id, client_id)
);
alter table user_favourites
owner to postgres;
create table product_favourites
(
product_id integer not null
constraint product_id_fk
references product (id)
on delete cascade ,
client_id integer not null
constraint user_fk
references client (id)
on delete cascade ,
primary key (product_id, client_id)
);
alter table product_favourites
owner to postgres;
create table bid
(
id serial,
publish_date timestamp not null ,
amount double precision not null,
product_id integer not null
constraint product_fk
references product (id)
on delete cascade ,
client_id integer not null
constraint user_fk
references client (id)
on delete cascade ,
primary key (id, product_id, client_id)
);
alter table bid
owner to postgres;
create table session
(
id serial,
start_date timestamp not null ,
finish_date timestamp ,
login_id integer not null
constraint login_credentials_fk
references login_credentials (id)
on delete cascade ,
primary key (id, login_id)
);
alter table session
owner to postgres;