| 1 | drop table if exists Dorm_User;
|
|---|
| 2 | drop table if exists Student;
|
|---|
| 3 | drop table if exists Employee;
|
|---|
| 4 | drop table if exists Payment;
|
|---|
| 5 | drop table if exists Dorm_Document;
|
|---|
| 6 | drop table if exists Block;
|
|---|
| 7 | drop table if exists Room;
|
|---|
| 8 | drop table if exists RoomRequest;
|
|---|
| 9 | drop table if exists StudentTookRoom;
|
|---|
| 10 |
|
|---|
| 11 | create table Dorm_User(
|
|---|
| 12 | u_id bigint primary key,
|
|---|
| 13 | phone_number varchar(10) not null,
|
|---|
| 14 | first_name varchar(30) not null,
|
|---|
| 15 | last_name varchar(50) not null,
|
|---|
| 16 | email varchar(1000) not null unique,
|
|---|
| 17 | pass varchar(15) not null
|
|---|
| 18 | );
|
|---|
| 19 |
|
|---|
| 20 | create table Student(
|
|---|
| 21 | u_id bigint primary key references Dorm_User(u_id),
|
|---|
| 22 | faculty_name varchar(255) not null,
|
|---|
| 23 | year_of_studies integer not null,
|
|---|
| 24 | is_exempt boolean not null
|
|---|
| 25 | );
|
|---|
| 26 |
|
|---|
| 27 | create table Employee(
|
|---|
| 28 | u_id bigint primary key references Dorm_User(u_id)
|
|---|
| 29 | );
|
|---|
| 30 |
|
|---|
| 31 | create table Payment(
|
|---|
| 32 | p_id bigint primary key,
|
|---|
| 33 | amount integer not null,
|
|---|
| 34 | payment_date date not null,
|
|---|
| 35 | student_id bigint,
|
|---|
| 36 | payment_month varchar(15) not null,
|
|---|
| 37 | constraint payment_fk_kon_student foreign key (student_id) references Student(u_id)
|
|---|
| 38 | );
|
|---|
| 39 |
|
|---|
| 40 | create table Dorm_Document(
|
|---|
| 41 | d_id bigint primary key,
|
|---|
| 42 | d_comment varchar(1000),
|
|---|
| 43 | d_status varchar(10) not null,
|
|---|
| 44 | upload_date date not null,
|
|---|
| 45 | file_path varchar(1000) not null,
|
|---|
| 46 | emp_id bigint,
|
|---|
| 47 | student_id bigint,
|
|---|
| 48 | constraint Dorm_Document_fkey_kon_Employee foreign key(emp_id) references Employee(u_id),
|
|---|
| 49 | constraint Dorm_Document_fkey_kon_Student foreign key(student_id) references Student(u_id)
|
|---|
| 50 | );
|
|---|
| 51 |
|
|---|
| 52 | create table Block(
|
|---|
| 53 | block_id char(1) primary key,
|
|---|
| 54 | num_available_rooms integer not null
|
|---|
| 55 | );
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | create table Room(
|
|---|
| 59 | room_number integer,
|
|---|
| 60 | block_id char(1),
|
|---|
| 61 | is_available boolean not null,
|
|---|
| 62 | capacity integer not null,
|
|---|
| 63 | constraint Room_pkey primary key(room_number, block_id),
|
|---|
| 64 | constraint Room_fk_kon_Block foreign key(block_id) references Block(block_id)
|
|---|
| 65 | );
|
|---|
| 66 |
|
|---|
| 67 | create table RoomRequest(
|
|---|
| 68 | status varchar(10) not null,
|
|---|
| 69 | roomate_email varchar(1000),
|
|---|
| 70 | room_number integer,
|
|---|
| 71 | block_id varchar(1),
|
|---|
| 72 | employee_id bigint,
|
|---|
| 73 | student_id bigint,
|
|---|
| 74 | constraint RoomRequest_pkey primary key(room_number, block_id, student_id),
|
|---|
| 75 | constraint student_id foreign key(student_id) references Student(u_id),
|
|---|
| 76 | constraint StudentTookRoom_fkey_kon_Room foreign key(room_number, block_id) references Room(room_number, block_id),
|
|---|
| 77 | constraint employee_id foreign key(employee_id) references Employee(u_id)
|
|---|
| 78 | );
|
|---|
| 79 |
|
|---|
| 80 | create table StudentTookRoom(
|
|---|
| 81 | start_date date not null,
|
|---|
| 82 | end_date date,
|
|---|
| 83 | student_id bigint,
|
|---|
| 84 | room_num integer,
|
|---|
| 85 | block_id char(1),
|
|---|
| 86 | constraint StudentTookRoom_pkey primary key(student_id, room_num, block_id),
|
|---|
| 87 | constraint StudentTookRoom_fkey_kon_Student foreign key(student_id) references Student(u_id),
|
|---|
| 88 | constraint StudentTookRoom_fkey_kon_Room foreign key(room_num, block_id) references Room(room_number, block_id)
|
|---|
| 89 | );
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|