1 | create table korisnik(
|
---|
2 | user_id serial primary key,
|
---|
3 | user_ime varchar(50) not null,
|
---|
4 | user_prezime varchar(50) not null,
|
---|
5 | user_password varchar(300) not null,
|
---|
6 | user_admin_id integer not null
|
---|
7 | --treba fk da se dodade do sistemski_admin so alter table
|
---|
8 | );
|
---|
9 |
|
---|
10 | create table sistemski_admin(
|
---|
11 | user_id integer primary key,
|
---|
12 | constraint fk_user foreign key (user_id) references korisnik (user_id)
|
---|
13 | on delete cascade on update cascade
|
---|
14 | );
|
---|
15 |
|
---|
16 | alter table korisnik add constraint fk_korisnik_administriran foreign key (user_admin_id) references sistemski_admin(user_id)
|
---|
17 | on delete cascade on update cascade;
|
---|
18 |
|
---|
19 | create table kupuvac(
|
---|
20 | user_id serial primary key,
|
---|
21 | kupuvac_tel_broj varchar(50) not null,
|
---|
22 | constraint fk_user foreign key (user_id) references korisnik (user_id)
|
---|
23 | on delete cascade on update cascade
|
---|
24 | );
|
---|
25 |
|
---|
26 | create table dostavuvac(
|
---|
27 | user_id serial primary key,
|
---|
28 | dostavuvac_vraboten_od date not null,
|
---|
29 | constraint fk_user foreign key (user_id) references korisnik (user_id)
|
---|
30 | on delete cascade on update cascade
|
---|
31 | );
|
---|
32 |
|
---|
33 | create table menadzer(
|
---|
34 | user_id serial primary key,
|
---|
35 | menadzer_vraboten_od date not null,
|
---|
36 | constraint fk_user foreign key (user_id) references korisnik (user_id)
|
---|
37 | on delete cascade on update cascade
|
---|
38 | );
|
---|
39 |
|
---|
40 | create table restoran(
|
---|
41 | restoran_id serial primary key,
|
---|
42 | restoran_ime varchar(50) not null,
|
---|
43 | restoran_rejting integer not null,
|
---|
44 | restoran_adresa varchar(50) not NULL,
|
---|
45 | user_id integer NOT null,
|
---|
46 | constraint fk_restoran_menadzer foreign key(user_id) references menadzer(user_id) on delete cascade on update cascade
|
---|
47 | );
|
---|
48 |
|
---|
49 | create table tip(
|
---|
50 | tip_id serial primary key,
|
---|
51 | tip_ime varchar(50) not null
|
---|
52 | );
|
---|
53 |
|
---|
54 | create table meni(
|
---|
55 | meni_id serial primary key,
|
---|
56 | tip_id integer not null,
|
---|
57 | restoran_id integer not null,
|
---|
58 | constraint fk_meni_tip foreign key (tip_id) references tip(tip_id) on delete cascade on update cascade,
|
---|
59 | constraint fk_meni_restoran foreign key (restoran_id) references restoran(restoran_id) on delete cascade on update cascade
|
---|
60 | );
|
---|
61 |
|
---|
62 | create table obrok(
|
---|
63 | obrok_id serial primary key,
|
---|
64 | obrok_opis varchar(10000) not null,
|
---|
65 | obrok_ime varchar(50) not null,
|
---|
66 | meni_id integer not null,
|
---|
67 | constraint fk_obrok_meni foreign key(meni_id) references meni(meni_id) on delete cascade on update cascade
|
---|
68 | );
|
---|
69 |
|
---|
70 | create table rezervacija(
|
---|
71 | rezervacija_id serial primary key,
|
---|
72 | rezervacija_vreme timestamp not null,
|
---|
73 | br_lugje integer not null,
|
---|
74 | rezervacija_status varchar(50) not null,
|
---|
75 | rezervacija_opis varchar(10000) not null,
|
---|
76 | restoran_id integer not null,
|
---|
77 | user_id integer not null,
|
---|
78 | constraint fk_rezervacija_restoran foreign key(restoran_id) references restoran(restoran_id) on delete cascade on update cascade,
|
---|
79 | constraint fk_rezervacija_kupuvac foreign key (user_id) references kupuvac(user_id) on delete cascade on update cascade
|
---|
80 | );
|
---|
81 |
|
---|
82 | create table naracka(
|
---|
83 | naracka_id serial primary key,
|
---|
84 | naracana_na timestamp not null,
|
---|
85 | naracka_status varchar(50) not null,
|
---|
86 | naracka_cena_vkupna integer not null,
|
---|
87 | user_id_kupuvac integer not null,
|
---|
88 | user_id_dostavuvac integer not null,
|
---|
89 | constraint fk_naracka_kupuvac foreign key (user_id_kupuvac) references kupuvac(user_id) on delete cascade on update cascade,
|
---|
90 | constraint fk_naracka_dostavuvac foreign key(user_id_dostavuvac) references dostavuvac(user_id)on delete cascade on update cascade
|
---|
91 | );
|
---|
92 |
|
---|
93 | create table restoran_tel_broj(
|
---|
94 | restoran_id integer not null,
|
---|
95 | broj varchar(50),
|
---|
96 | constraint pk_restoran_tel_broj primary key (restoran_id,broj),
|
---|
97 | constraint fk_restoran_tel_broj_restoran foreign key(restoran_id) references restoran(restoran_id) on delete cascade on update cascade
|
---|
98 | );
|
---|
99 |
|
---|
100 | create table cena(
|
---|
101 | obrok_id integer not null,
|
---|
102 | cena_id integer not null,
|
---|
103 | cena_iznos integer not null,
|
---|
104 | cena_vazi_od date not null,
|
---|
105 | cena_vazi_do date not null,
|
---|
106 | constraint pk_cena primary key (obrok_id,cena_id),
|
---|
107 | constraint fk_cena_obrok foreign key (obrok_id) references obrok(obrok_id) on delete cascade on update cascade
|
---|
108 | );
|
---|
109 |
|
---|
110 | create table rezervira(
|
---|
111 | rezervacija_id integer not null,
|
---|
112 | obrok_id integer not null,
|
---|
113 | constraint pk_rezervira primary key(rezervacija_id,obrok_id),
|
---|
114 | constraint fk_rezervira_rezervacija foreign key (rezervacija_id) references rezervacija(rezervacija_id) on delete cascade on update cascade,
|
---|
115 | constraint fk_rezervira_obrok foreign key (obrok_id) references obrok(obrok_id) on delete cascade on update cascade
|
---|
116 | );
|
---|
117 |
|
---|
118 | create table se_sostoi_od(
|
---|
119 | naracka_id integer not null,
|
---|
120 | obrok_id integer not null,
|
---|
121 | kolicina integer not null,
|
---|
122 | cena integer not null,
|
---|
123 | constraint pk_se_sostoi_od primary key (naracka_id,obrok_id),
|
---|
124 | constraint fk_se_sostoi_od_naracka foreign key (naracka_id) references naracka(naracka_id) on delete cascade on update cascade,
|
---|
125 | constraint fk_se_sostoi_od_obrok foreign key (obrok_id) references obrok(obrok_id) on delete cascade on update cascade
|
---|
126 | );
|
---|
127 |
|
---|
128 | -- drop tables
|
---|
129 | drop table korisnik;
|
---|
130 | drop table sistemski_admin;
|
---|
131 | drop table kupuvac;
|
---|
132 | drop table dostavuvac;
|
---|
133 | drop table menadzer;
|
---|
134 | drop table restoran;
|
---|
135 | drop table tip;
|
---|
136 | drop table meni;
|
---|
137 | drop table obrok;
|
---|
138 | drop table rezervacija;
|
---|
139 | drop table naracka;
|
---|
140 | drop table restoran_tel_broj;
|
---|
141 | drop table cena;
|
---|
142 | drop table rezervira;
|
---|
143 | drop table se_sostoi_od;
|
---|