-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
189 lines (169 loc) · 5.28 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
-- Table property
CREATE TABLE property (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR NOT NULL,
address_line1 VARCHAR NOT NULL,
address_line2 VARCHAR,
city VARCHAR NOT NULL,
region VARCHAR NOT NULL,
property_type_id INTEGER NOT NULL,
property_size INTEGER NOT NULL,
block_size INTEGER NOT NULL,
num_bedrooms INTEGER NOT NULL,
num_bathrooms INTEGER NOT NULL,
num_carspaces INTEGER NOT NULL,
images_id INTEGER NOT NULL,
description VARCHAR,
FOREIGN KEY (property_type_id) REFERENCES property_type(id),
FOREIGN KEY (images_id) REFERENCES images(id)
);
-- Table property_type
CREATE TABLE images(
id INTEGER PRIMARY KEY AUTOINCREMENT,
value VARCHAR NOT NULL
);
-- Table property_images
CREATE TABLE property_image (
property_id INTEGER NOT NULL,
image_id INTEGER NOT NULL,
FOREIGN KEY (property_id) REFERENCES property(id)
FOREIGN KEY (image_id) REFERENCES images(id)
);
-- Table property_type
CREATE TABLE property_type (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description VARCHAR NOT NULL
);
-- Table listing_type
CREATE TABLE listing_type (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description VARCHAR NOT NULL
);
-- Table listing_status
CREATE TABLE listing_status (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description VARCHAR NOT NULL
);
-- Table feature
CREATE TABLE feature (
id INTEGER PRIMARY KEY AUTOINCREMENT,
feature_name VARCHAR NOT NULL
);
-- Table property_feature
CREATE TABLE property_feature (
property_id INTEGER,
feature_id INTEGER,
PRIMARY KEY (property_id, feature_id),
FOREIGN KEY (property_id) REFERENCES property(id),
FOREIGN KEY (feature_id) REFERENCES feature(id)
);
-- Table listing
CREATE TABLE listing (
id INTEGER PRIMARY KEY AUTOINCREMENT,
property_id INTEGER NOT NULL,
listing_status_id INTEGER NOT NULL,
listing_type_id INTEGER NOT NULL,
price INTEGER NOT NULL,
created_date DATE NOT NULL,
FOREIGN KEY (property_id) REFERENCES property(id),
FOREIGN KEY (listing_status_id) REFERENCES listing_status(id),
FOREIGN KEY (listing_type_id) REFERENCES listing_type(id)
);
-- Table employee
CREATE TABLE employee (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
start_date DATE NOT NULL,
end_date DATE,
job_title VARCHAR NOT NULL
);
-- Table property_employee
CREATE TABLE property_employee (
property_id INTEGER,
employee_id INTEGER,
role_type_id INTEGER,
start_date DATE NOT NULL,
end_date DATE,
PRIMARY KEY (property_id, employee_id, role_type_id),
FOREIGN KEY (property_id) REFERENCES property(id),
FOREIGN KEY (employee_id) REFERENCES employee(id),
FOREIGN KEY (role_type_id) REFERENCES role_type(id)
);
-- Table role_type
CREATE TABLE role_type (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description VARCHAR NOT NULL
);
-- Table inspection
CREATE TABLE inspection (
id INTEGER PRIMARY KEY AUTOINCREMENT,
property_id INTEGER NOT NULL,
inspection_datetime DATETIME NOT NULL,
responsible_employee_id INTEGER NOT NULL,
FOREIGN KEY (property_id) REFERENCES property(id),
FOREIGN KEY (responsible_employee_id) REFERENCES employee(id)
);
-- Table client
CREATE TABLE client (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
email_address VARCHAR NOT NULL,
phone_number VARCHAR NOT NULL
);
-- Table client_property_interest
CREATE TABLE client_property_interest (
client_id INTEGER,
property_id INTEGER,
PRIMARY KEY (client_id, property_id),
FOREIGN KEY (client_id) REFERENCES client(id),
FOREIGN KEY (property_id) REFERENCES property(id)
);
-- Table client_inspection
CREATE TABLE client_inspection (
client_id INTEGER,
inspection_id INTEGER,
PRIMARY KEY (client_id, inspection_id),
FOREIGN KEY (client_id) REFERENCES client(id),
FOREIGN KEY (inspection_id) REFERENCES inspection(id)
);
-- Table offer
CREATE TABLE offer (
id INTEGER PRIMARY KEY AUTOINCREMENT,
client_id INTEGER NOT NULL,
property_id INTEGER NOT NULL,
offer_status_id INTEGER NOT NULL,
offer_amount INTEGER NOT NULL,
FOREIGN KEY (client_id) REFERENCES client(id),
FOREIGN KEY (property_id) REFERENCES property(id),
FOREIGN KEY (offer_status_id) REFERENCES offer_status(id)
);
-- Table offer_status
CREATE TABLE offer_status (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description VARCHAR NOT NULL
);
-- Table contract
CREATE TABLE contract (
id INTEGER PRIMARY KEY AUTOINCREMENT,
property_id INTEGER NOT NULL,
listing_type_id INTEGER NOT NULL,
contract_document VARCHAR NOT NULL,
responsible_employee_id INTEGER NOT NULL,
client_id INTEGER NOT NULL,
contract_status_id INTEGER NOT NULL,
signed_date DATE NOT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
FOREIGN KEY (property_id) REFERENCES property(id),
FOREIGN KEY (listing_type_id) REFERENCES listing_type(id),
FOREIGN KEY (responsible_employee_id) REFERENCES employee(id),
FOREIGN KEY (client_id) REFERENCES client(id),
FOREIGN KEY (contract_status_id) REFERENCES contract_status(id)
);
-- Table contract_status
CREATE TABLE contract_status (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description VARCHAR NOT NULL
);