1 | drop table if exists Service;
|
---|
2 | drop table if exists Payment;
|
---|
3 | drop table if exists Reservation;
|
---|
4 | drop table if exists Room;
|
---|
5 | drop table if exists Staff;
|
---|
6 | drop table if exists Customer;
|
---|
7 | drop table if exists Manager;
|
---|
8 | drop table if exists Hotel_Building;
|
---|
9 | drop table if exists Hotel_User;
|
---|
10 |
|
---|
11 |
|
---|
12 | create table Hotel_User(
|
---|
13 | user_id bigint primary key,
|
---|
14 | first_name varchar(30) not null,
|
---|
15 | last_name varchar(30) not null,
|
---|
16 | phone varchar(9) not null,
|
---|
17 | email varchar(100) not null unique,
|
---|
18 | password varchar(100) not null
|
---|
19 | );
|
---|
20 |
|
---|
21 |
|
---|
22 | create table Staff(
|
---|
23 | user_id bigint primary key,
|
---|
24 | constraint staff_fk foreign key (user_id) references Hotel_User(user_id) on delete cascade
|
---|
25 | );
|
---|
26 |
|
---|
27 |
|
---|
28 | create table Customer(
|
---|
29 | user_id bigint primary key,
|
---|
30 | constraint customer_fk foreign key (user_id) references Hotel_User(user_id) on delete cascade
|
---|
31 | );
|
---|
32 |
|
---|
33 |
|
---|
34 | create table Manager(
|
---|
35 | user_id bigint primary key,
|
---|
36 | constraint manager_fk foreign key (user_id) references Hotel_User(user_id) on delete cascade
|
---|
37 | );
|
---|
38 |
|
---|
39 | create table Hotel_Building(
|
---|
40 | building_id varchar(10) primary key,
|
---|
41 | address varchar(50) not null,
|
---|
42 | city varchar(20) not null,
|
---|
43 | floor integer not null,
|
---|
44 | num_rooms integer not null
|
---|
45 | );
|
---|
46 |
|
---|
47 |
|
---|
48 | create table Room(
|
---|
49 | room_number integer,
|
---|
50 | room_type varchar(20) not null,
|
---|
51 | number_of_beds integer not null,
|
---|
52 | price_per_night bigint not null,
|
---|
53 | available boolean not null,
|
---|
54 | building_id varchar(10),
|
---|
55 | constraint room_pkey primary key (room_number, building_id),
|
---|
56 | constraint room_fk foreign key (building_id) references Hotel_Building(building_id)
|
---|
57 | );
|
---|
58 |
|
---|
59 | create table Reservation(
|
---|
60 | reservation_id bigint primary key,
|
---|
61 | start_date date not null,
|
---|
62 | end_date date,
|
---|
63 | status varchar(40) not null,
|
---|
64 | reserv_date date not null,
|
---|
65 | room_number integer,
|
---|
66 | building_id varchar(10),
|
---|
67 | customer_id bigint,
|
---|
68 | manager_id bigint,
|
---|
69 | constraint reservation_fk_room foreign key(room_number, building_id) references Room(room_number, building_id),
|
---|
70 | constraint reservation_fk_customer foreign key(customer_id) references Customer(user_id),
|
---|
71 | constraint reservation_fk_manager foreign key(manager_id) references Manager(user_id)
|
---|
72 | );
|
---|
73 |
|
---|
74 | create table Payment(
|
---|
75 | p_id bigint primary key,
|
---|
76 | p_method varchar(5) not null,
|
---|
77 | amount integer not null,
|
---|
78 | p_date date not null,
|
---|
79 | customer_id bigint,
|
---|
80 | reservation_id bigint,
|
---|
81 | constraint payment_fk_reservation foreign key (reservation_id) references Reservation(reservation_id),
|
---|
82 | constraint payment_fk foreign key (customer_id) references Customer(user_id)
|
---|
83 | );
|
---|
84 |
|
---|
85 |
|
---|
86 | create table Service(
|
---|
87 | service_id bigint primary key,
|
---|
88 | service_type varchar(40) not null,
|
---|
89 | service_date date,
|
---|
90 | service_status varchar(70) not null,
|
---|
91 | room_number integer,
|
---|
92 | building_id varchar(10),
|
---|
93 | staff_id bigint,
|
---|
94 | CONSTRAINT service_fk_room FOREIGN KEY (room_number, building_id) REFERENCES Room(room_number, building_id),
|
---|
95 | CONSTRAINT service_fk_staff FOREIGN KEY (staff_id) REFERENCES Staff(user_id)
|
---|
96 | );
|
---|