-
Notifications
You must be signed in to change notification settings - Fork 0
/
pickFix_test.sql
70 lines (62 loc) · 1.87 KB
/
pickFix_test.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
CREATE TABLE contractors(
id SERIAL PRIMARY KEY,
name TEXT,
firstname TEXT NOT NULL,
lastname TEXT NOT NULL,
email TEXT NOT NULL,
password TEXT NOT NULL
);
CREATE TABLE customers(
id SERIAL PRIMARY KEY,
firstname TEXT NOT NULL,
lastname TEXT NOT NULL,
email TEXT NOT NULL,
password TEXT NOT NULL
);
CREATE TABLE projects(
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
description TEXT NOT NULL,
status TEXT NOT NULL,
--REQUESTED, ACCEPTED, ACTIVE, COMPLETED, DECLINED
budget INT,
customer_id INT NOT NULL REFERENCES customers ON DELETE NO ACTION,
contractor_id INT NOT NULL REFERENCES contractors ON DELETE NO ACTION,
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP
);
CREATE TABLE project_chats(
id SERIAL PRIMARY KEY,
project_id INT NOT NULL REFERENCES projects ON DELETE CASCADE,
chat TEXT NOT NULL,
created_on TIMESTAMP,
customer_id INT REFERENCES customers ON DELETE CASCADE,
contractor_id INT REFERENCES contractors ON DELETE CASCADE,
sent_by TEXT NOT NULL
);
CREATE TABLE project_reviews(
id SERIAL PRIMARY KEY,
project_id INT NOT NULL REFERENCES projects ON DELETE CASCADE,
rating DECIMAL(6,1) NOT NULL CHECK (rating BETWEEN 0 AND 5.0),
comment TEXT NOT NULL,
created_on TIMESTAMP,
customer_id INT REFERENCES customers ON DELETE CASCADE,
contractor_id INT REFERENCES contractors ON DELETE CASCADE,
sent_by TEXT NOT NULL
);
CREATE TABLE user_locations(
id SERIAL PRIMARY KEY,
user_id INT NOT NULL,
user_type TEXT NOT NULL,
lat NUMERIC NOT NULL,
lng NUMERIC NOT NULL
);
CREATE TABLE user_events(
id SERIAL PRIMARY KEY,
user_id INT NOT NULL,
user_type TEXT NOT NULL,
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP,
available BOOLEAN,
project INT NOT NULL REFERENCES projects ON DELETE CASCADE
);