-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema.sql
84 lines (74 loc) · 3.29 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
CREATE TABLE tb_additional (
id BIGINT NOT NULL,
name VARCHAR(255),
description TEXT,
price DOUBLE PRECISION,
type VARCHAR(255),
PRIMARY KEY (id)
);
CREATE TABLE tb_clients (
id BIGINT NOT NULL,
country VARCHAR(255),
cpf VARCHAR(255),
passport VARCHAR(255),
fullName VARCHAR(255),
birthDate DATE,
address VARCHAR(255),
phone VARCHAR(255),
email VARCHAR(255),
PRIMARY KEY (id)
);
CREATE TABLE tb_location (
id BIGINT NOT NULL,
name VARCHAR(255),
address VARCHAR(255),
zipCode VARCHAR(255),
city VARCHAR(255),
state VARCHAR(255),
PRIMARY KEY (id)
);
CREATE TABLE tb_building (
id BIGINT NOT NULL,
location_id BIGINT,
name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (location_id) REFERENCES tb_location(id)
);
CREATE TABLE tb_room (
id BIGINT NOT NULL,
building_id BIGINT,
location_id BIGINT,
type VARCHAR(255),
totalPeople INT,
totalBeds INT,
otherFurniture VARCHAR(255),
bathroom VARCHAR(255),
dailyRate DOUBLE PRECISION,
PRIMARY KEY (id),
FOREIGN KEY (building_id) REFERENCES tb_building(id),
FOREIGN KEY (location_id) REFERENCES tb_location(id)
);
CREATE TABLE tb_bookings (
id BIGINT NOT NULL,
id_client BIGINT,
checkInDate DATE,
checkOutDate DATE,
totalValue DOUBLE PRECISION,
guests INT,
PRIMARY KEY (id),
FOREIGN KEY (id_client) REFERENCES tb_clients(id)
);
CREATE TABLE rooms_booked (
book_id BIGINT NOT NULL,
room_id BIGINT NOT NULL,
PRIMARY KEY (book_id, room_id),
FOREIGN KEY (book_id) REFERENCES tb_bookings(id),
FOREIGN KEY (room_id) REFERENCES tb_room(id)
);
CREATE TABLE services_booked (
book_id BIGINT NOT NULL,
service_id BIGINT NOT NULL,
PRIMARY KEY (book_id, service_id),
FOREIGN KEY (book_id) REFERENCES tb_bookings(id),
FOREIGN KEY (service_id) REFERENCES tb_additional(id)
);