-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
38 lines (34 loc) · 1.01 KB
/
database.sql
File metadata and controls
38 lines (34 loc) · 1.01 KB
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
CREATE TABLE appartement(
appartement_id INT AUTO_INCREMENT,
area INT,
capacity INT,
streetNumber INT,
streetName VARCHAR(255),
city VARCHAR(255),
disponibility BOOL NOT NULL DEFAULT 1,
PRIMARY KEY(appartement_id)
);
CREATE TABLE appUser(
user_id INT AUTO_INCREMENT,
admin BOOL NOT NULL DEFAULT 0,
api_key VARCHAR(255) NOT NULL,
PRIMARY KEY(user_id)
);
CREATE TABLE own(
appartement_id INT,
user_id INT,
PRIMARY KEY(appartement_id, user_id),
FOREIGN KEY(appartement_id) REFERENCES appartement(appartement_id),
FOREIGN KEY(user_id) REFERENCES appUser(user_id)
);
CREATE TABLE rent(
appartement_id INT,
user_id INT,
date_begin DATE NOT NULL,
date_end DATE NOT NULL,
price DECIMAL(12, 2) NOT NULL,
PRIMARY KEY(appartement_id, user_id),
FOREIGN KEY(appartement_id) REFERENCES appartement(appartement_id),
FOREIGN KEY(user_id) REFERENCES appUser(user_id)
);
INSERT INTO appUser(user_id, admin, api_key) VALUES (0, 1, "admin");