| 1 | drop schema if exists project cascade;
|
|---|
| 2 | create schema project;
|
|---|
| 3 |
|
|---|
| 4 | --use project
|
|---|
| 5 |
|
|---|
| 6 | drop table if exists users cascade;
|
|---|
| 7 | drop table if exists movie cascade;
|
|---|
| 8 | drop table if exists employee cascade;
|
|---|
| 9 | drop table if exists genre cascade;
|
|---|
| 10 | drop table if exists movieProjection cascade;
|
|---|
| 11 | drop table if exists firm cascade;
|
|---|
| 12 | drop table if exists auditorium cascade;
|
|---|
| 13 | drop table if exists seat cascade;
|
|---|
| 14 | drop table if exists client cascade;
|
|---|
| 15 | drop table if exists payment cascade;
|
|---|
| 16 | drop table if exists Payment_Type cascade;
|
|---|
| 17 | drop table if exists is_ cascade;
|
|---|
| 18 | drop table if exists controles cascade;
|
|---|
| 19 |
|
|---|
| 20 | ------------------------------------------------------
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | create table users(
|
|---|
| 24 |
|
|---|
| 25 | user_id serial primary key,
|
|---|
| 26 | user_username varchar(150) not null,
|
|---|
| 27 | user_password varchar(150) not null,
|
|---|
| 28 | user_phone_number varchar(150),
|
|---|
| 29 | user_name varchar(150) not null,
|
|---|
| 30 | user_surname varchar(150) not null,
|
|---|
| 31 | user_email varchar(150) ,
|
|---|
| 32 | user_role varchar(100)
|
|---|
| 33 |
|
|---|
| 34 | );
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | ------------------------------------------------------
|
|---|
| 38 |
|
|---|
| 39 | create table employee(
|
|---|
| 40 |
|
|---|
| 41 | employee_id serial,
|
|---|
| 42 | user_id integer not null,
|
|---|
| 43 | constraint fk_employee_users_ foreign key (user_id) references users(user_id),
|
|---|
| 44 | constraint pk_employee_users primary key (user_id)
|
|---|
| 45 |
|
|---|
| 46 | );
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | ------------------------------------------------------
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | create table client(
|
|---|
| 54 | client_id serial,
|
|---|
| 55 | user_id integer not null,
|
|---|
| 56 | constraint fk_client_users_ foreign key (user_id) references users(user_id),
|
|---|
| 57 | constraint pk_client_users primary key (user_id)
|
|---|
| 58 | );
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | ------------------------------------------------------
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | create table genre(
|
|---|
| 65 | genre_id serial primary key,
|
|---|
| 66 | genre_name varchar (150) not null
|
|---|
| 67 | );
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | ------------------------------------------------------
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | create table movie(
|
|---|
| 74 |
|
|---|
| 75 | movie_id integer primary key,
|
|---|
| 76 | movie_name varchar(150) not null,
|
|---|
| 77 | movie_age_category varchar(150) not null,
|
|---|
| 78 | movie_production varchar(150) not null,
|
|---|
| 79 | movie_film_director varchar(150) not null,
|
|---|
| 80 | movie_cast varchar(250) not null,
|
|---|
| 81 | movie_time_duration varchar(150) not null
|
|---|
| 82 |
|
|---|
| 83 | );
|
|---|
| 84 |
|
|---|
| 85 | ------------------------------------------------------
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | create table firm(
|
|---|
| 89 |
|
|---|
| 90 | firm_id serial primary key,
|
|---|
| 91 | firm_city varchar(100) not null,
|
|---|
| 92 | firm_adress varchar(100) not null,
|
|---|
| 93 | firm_name varchar(100) not null
|
|---|
| 94 |
|
|---|
| 95 | );
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | ------------------------------------------------------
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | create table auditorium(
|
|---|
| 102 | auditorium_id serial primary key,
|
|---|
| 103 | auditorium_name varchar(100) not null,
|
|---|
| 104 | auditorium_capacity integer not null,
|
|---|
| 105 |
|
|---|
| 106 | firm_id integer not null,
|
|---|
| 107 | constraint fk_auditorium_firm foreign key (firm_id) references firm(firm_id)
|
|---|
| 108 | );
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | ------------------------------------------------------
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | create table movieProjection(
|
|---|
| 115 | projection_id serial primary key,
|
|---|
| 116 | projection_movie_start varchar(150) not null,
|
|---|
| 117 | projection_movie_end varchar(150) not null,
|
|---|
| 118 | projection_screening_date varchar(150) not null,
|
|---|
| 119 | projection_type varchar(150) not null,
|
|---|
| 120 | projection_price float8 not null,
|
|---|
| 121 |
|
|---|
| 122 | movie_id integer not null,
|
|---|
| 123 | constraint fk_movieProjection_movie foreign key (movie_id) references movie(movie_id)
|
|---|
| 124 |
|
|---|
| 125 | );
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | ------------------------------------------------------
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | create table works_in(
|
|---|
| 132 | works_from varchar(150) not null,
|
|---|
| 133 | works_to varchar(150),
|
|---|
| 134 |
|
|---|
| 135 | user_id integer not null,
|
|---|
| 136 | firm_id integer not null,
|
|---|
| 137 |
|
|---|
| 138 | constraint pk_works_in_firm primary key (user_id,firm_id),
|
|---|
| 139 | constraint fk_works_in_firm foreign key (firm_id) references firm(firm_id),
|
|---|
| 140 | constraint fk_works_in_employee foreign key (user_id) references employee(user_id)
|
|---|
| 141 |
|
|---|
| 142 | );
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | ------------------------------------------------------
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | create table Payment_Type(
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | payment_type_id serial primary key,
|
|---|
| 152 | payment_type varchar(150) not null
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 | );
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | ------------------------------------------------------
|
|---|
| 159 |
|
|---|
| 160 | create table seat(
|
|---|
| 161 | seat_id serial ,
|
|---|
| 162 | seat_number integer not null,
|
|---|
| 163 | auditorium_id integer not null,
|
|---|
| 164 | constraint pk_seat_auditorium primary key (auditorium_id,seat_id),
|
|---|
| 165 | constraint fk_seat_auditorium foreign key (auditorium_id) references auditorium(auditorium_id)
|
|---|
| 166 | );
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 | ------------------------------------------------------
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | create table reservation(
|
|---|
| 173 | reservation_id serial primary key,
|
|---|
| 174 | reservation_date date not null,
|
|---|
| 175 | payment_type_id integer not null,
|
|---|
| 176 | constraint fk_reservation_Payment_Type foreign key (payment_type_id) references Payment_Type(payment_type_id),
|
|---|
| 177 | user_id integer not null,
|
|---|
| 178 | constraint fk_reservation_client foreign key (user_id) references client(user_id),
|
|---|
| 179 | auditorium_id integer not null,
|
|---|
| 180 | seat_id integer not null,
|
|---|
| 181 | constraint fk_seat_id foreign key (auditorium_id,seat_id) references seat(auditorium_id,seat_id),
|
|---|
| 182 | projection_id integer not null,
|
|---|
| 183 | constraint fk_reservation_movieProjection foreign key (projection_id) references movieProjection(projection_id)
|
|---|
| 184 | );
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | ------------------------------------------------------
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | create table payment(
|
|---|
| 193 | payment_id serial primary key,
|
|---|
| 194 | payment_date date not null,
|
|---|
| 195 | user_id integer not null,
|
|---|
| 196 | constraint fk_payment_client foreign key (user_id) references client(user_id),
|
|---|
| 197 | payment_type_id integer not null,
|
|---|
| 198 | constraint fk_payment_payment_type foreign key (payment_type_id) references payment_type(payment_type_id),
|
|---|
| 199 | reservation_id integer not null,
|
|---|
| 200 | constraint fk_payment_reservation foreign key (reservation_id) references reservation(reservation_id)
|
|---|
| 201 | );
|
|---|
| 202 |
|
|---|
| 203 | ------------------------------------------------------
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 | create table controles(
|
|---|
| 207 | user_id integer not null,
|
|---|
| 208 | projection_id integer not null,
|
|---|
| 209 | constraint pk_controles_user primary key (user_id,projection_id),
|
|---|
| 210 | constraint fk_controles_employee foreign key (user_id) references employee(user_id),
|
|---|
| 211 | constraint fk_controles_movieProjection foreign key (projection_id) references movieProjection(projection_id)
|
|---|
| 212 | );
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | ------------------------------------------------------
|
|---|
| 216 |
|
|---|
| 217 | create table is_(
|
|---|
| 218 | genre_id integer not null,
|
|---|
| 219 | movie_id integer not null,
|
|---|
| 220 | constraint pk_is_genre primary key (movie_id,genre_id),
|
|---|
| 221 | constraint fk_is_movie foreign key (movie_id) references movie(movie_id),
|
|---|
| 222 | constraint fk_controles_genre foreign key (genre_id) references genre(genre_id)
|
|---|
| 223 | );
|
|---|
| 224 |
|
|---|
| 225 | ------------------------------------------------------
|
|---|
| 226 |
|
|---|
| 227 | create table gives(
|
|---|
| 228 | seat_limitation integer not null,
|
|---|
| 229 | projection_id integer not null,
|
|---|
| 230 | auditorium_id integer not null,
|
|---|
| 231 | constraint fk_gives_movieProjection foreign key (projection_id) references movieProjection(projection_id),
|
|---|
| 232 | constraint fk_gives_auditorium foreign key (auditorium_id) references auditorium(auditorium_id),
|
|---|
| 233 | constraint pk_gives_movieProjection primary key (auditorium_id,projection_id)
|
|---|
| 234 | );
|
|---|
| 235 |
|
|---|
| 236 | ------------------------------------------------------
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|