| 1 | -- delete tables if they exist
|
|---|
| 2 | drop table if exists project.Fakturi;
|
|---|
| 3 | drop table if exists project.Licenci;
|
|---|
| 4 | drop table if exists project.Rezervacii;
|
|---|
| 5 | drop table if exists project.Ruti;
|
|---|
| 6 | drop table if exists project.Vozila;
|
|---|
| 7 | drop table if exists project.Administratori;
|
|---|
| 8 | drop table if exists project.Dispeceri;
|
|---|
| 9 | drop table if exists project.Vozaci;
|
|---|
| 10 | drop table if exists project.Vraboteni_telefoni;
|
|---|
| 11 | drop table if exists project.Vraboteni;
|
|---|
| 12 | drop table if exists project.Tipovi;
|
|---|
| 13 | drop table if exists project.Roba;
|
|---|
| 14 | drop table if exists project.Kategorii;
|
|---|
| 15 | drop table if exists project.Kompanii;
|
|---|
| 16 | drop table if exists project.Gradovi;
|
|---|
| 17 | drop table if exists project.Klienti;
|
|---|
| 18 |
|
|---|
| 19 | -- create tables
|
|---|
| 20 | -- Kompanii: Kompanii(kompanija_id, kompanija_ime, kompanija_adresa, kompanija_telefon)
|
|---|
| 21 | create table project.Kompanii(
|
|---|
| 22 | kompanija_id serial not null,
|
|---|
| 23 | kompanija_ime varchar(300) not null,
|
|---|
| 24 | kompanija_adresa varchar(300) not null,
|
|---|
| 25 | kompanija_telefon varchar(300) not null,
|
|---|
| 26 |
|
|---|
| 27 | constraint pk_Kompanii primary key (kompanija_id),
|
|---|
| 28 | constraint un_Kompanii_kompanija_ime unique (kompanija_ime)
|
|---|
| 29 | );
|
|---|
| 30 |
|
|---|
| 31 | -- Vraboteni: Vraboteni(vraboten_id, vraboten_ime, vraboten_prezime, vraboten_email, kompanija_id*(Kompanii))
|
|---|
| 32 | create table project.Vraboteni(
|
|---|
| 33 | vraboten_id serial not null,
|
|---|
| 34 | vraboten_ime varchar(300) not null,
|
|---|
| 35 | vraboten_prezime varchar(300) not null,
|
|---|
| 36 | vraboten_email varchar(300) not null,
|
|---|
| 37 |
|
|---|
| 38 | kompanija_id integer not null,
|
|---|
| 39 |
|
|---|
| 40 | constraint pk_Vraboteni primary key (vraboten_id),
|
|---|
| 41 | constraint fk_Vraboteni_Kompanii foreign key (kompanija_id) references project.Kompanii(kompanija_id)
|
|---|
| 42 | );
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | -- Administratori: Administratori(administrator_id*(Vraboteni))
|
|---|
| 46 | create table project.Administratori(
|
|---|
| 47 | administrator_id integer not null,
|
|---|
| 48 |
|
|---|
| 49 | constraint pk_Administratori primary key (administrator_id),
|
|---|
| 50 | constraint fk_Administratori_Vraboteni foreign key (administrator_id) references project.Vraboteni(vraboten_id)
|
|---|
| 51 | );
|
|---|
| 52 |
|
|---|
| 53 | -- Dispeceri: Dispeceri(dispecer_id*(Vraboteni))
|
|---|
| 54 | create table project.Dispeceri(
|
|---|
| 55 | dispecer_id integer not null,
|
|---|
| 56 |
|
|---|
| 57 | constraint pk_Dispeceri primary key (dispecer_id),
|
|---|
| 58 | constraint fk_Dispeceri_Vraboteni foreign key (dispecer_id) references project.Vraboteni(vraboten_id)
|
|---|
| 59 | );
|
|---|
| 60 |
|
|---|
| 61 | -- Vozaci: Vozaci(vozac_id*(Vraboteni))
|
|---|
| 62 | create table project.Vozaci(
|
|---|
| 63 | vozac_id integer not null,
|
|---|
| 64 |
|
|---|
| 65 | constraint pk_Vozaci primary key (vozac_id),
|
|---|
| 66 | constraint fk_Vozaci_Vraboteni foreign key (vozac_id) references project.Vraboteni(vraboten_id)
|
|---|
| 67 | );
|
|---|
| 68 |
|
|---|
| 69 | -- Vraboteni_telefoni: Vraboteni_telefoni(vraboten_id*(Vraboteni), telefonski_broj)
|
|---|
| 70 | create table project.Vraboteni_telefoni(
|
|---|
| 71 | vraboten_id integer not null,
|
|---|
| 72 | telefonski_broj varchar(100) not null,
|
|---|
| 73 |
|
|---|
| 74 | constraint pk_Vraboteni_telefoni primary key (vraboten_id, telefonski_broj),
|
|---|
| 75 | constraint fk_Vraboteni_telefoni_Vraboteni foreign key (vraboten_id) references project.Vraboteni(vraboten_id)
|
|---|
| 76 | );
|
|---|
| 77 |
|
|---|
| 78 | -- Tipovi: Tipovi(tip_id, tip_ime)
|
|---|
| 79 | create table project.Tipovi(
|
|---|
| 80 | tip_id serial not null,
|
|---|
| 81 | tip_ime varchar(300) not null,
|
|---|
| 82 |
|
|---|
| 83 | constraint pk_Tipovi primary key (tip_id),
|
|---|
| 84 | constraint un_Tipovi_tip_ime unique (tip_ime)
|
|---|
| 85 | );
|
|---|
| 86 |
|
|---|
| 87 | -- Vozila: Vozila(vozilo_id, vozilo_kapacitet, kompanija_id*(Kompanii), tip_id*(Tipovi), vozac_id*(Vozaci))
|
|---|
| 88 | create table project.Vozila(
|
|---|
| 89 | vozilo_id integer not null,
|
|---|
| 90 | vozilo_kapacitet integer not null,
|
|---|
| 91 |
|
|---|
| 92 | kompanija_id integer not null,
|
|---|
| 93 | tip_id integer not null,
|
|---|
| 94 | vozac_id integer not null,
|
|---|
| 95 |
|
|---|
| 96 | constraint pk_Vozila primary key (vozilo_id),
|
|---|
| 97 | constraint fk_Vozila_Kompanii foreign key (kompanija_id) references project.Kompanii(kompanija_id),
|
|---|
| 98 | constraint fk_Vozila_Tipovi foreign key (tip_id) references project.Tipovi(tip_id),
|
|---|
| 99 | constraint fk_Vozila_Vozaci foreign key (vozac_id) references project.Vozaci(vozac_id)
|
|---|
| 100 | );
|
|---|
| 101 |
|
|---|
| 102 | -- Klienti: Klienti(klient_id, klient_ime, klient_prezime, klient_email, klient_telefon)
|
|---|
| 103 | create table project.Klienti(
|
|---|
| 104 | klient_id serial not null,
|
|---|
| 105 | klient_ime varchar(300) not null,
|
|---|
| 106 | klient_prezime varchar(300) not null,
|
|---|
| 107 | klient_email varchar(300) not null,
|
|---|
| 108 | klient_telefon varchar(100) not null,
|
|---|
| 109 |
|
|---|
| 110 | constraint pk_Klienti primary key (klient_id),
|
|---|
| 111 | constraint un_Klienti_klient_email unique (klient_email)
|
|---|
| 112 | );
|
|---|
| 113 |
|
|---|
| 114 | -- Gradovi: Gradovi(grad_id, grad_ime)
|
|---|
| 115 | create table project.Gradovi(
|
|---|
| 116 | grad_id serial not null,
|
|---|
| 117 | grad_ime varchar(300) not null,
|
|---|
| 118 |
|
|---|
| 119 | constraint pk_Gradovi primary key (grad_id),
|
|---|
| 120 | constraint un_Gradovi_ime unique (grad_ime)
|
|---|
| 121 | );
|
|---|
| 122 |
|
|---|
| 123 | -- Ruti: Ruti(ruta_id, datum_poagjanje, datum_pristignuvanje, vozilo_id*(Vozila),
|
|---|
| 124 | -- zapocnuva_vo*(Gradovi), zavrsuva_vo*(Gradovi), dispecer_id*(Dispeceri), vozac_id*(Vozaci))
|
|---|
| 125 | create table project.Ruti(
|
|---|
| 126 | ruta_id serial not null,
|
|---|
| 127 | datum_poagjanje date not null,
|
|---|
| 128 | datum_pristignuvanje date not null,
|
|---|
| 129 |
|
|---|
| 130 | vozilo_id integer not null,
|
|---|
| 131 | zapocnuva_vo integer not null,
|
|---|
| 132 | zavrsuva_vo integer not null,
|
|---|
| 133 | dispecer_id integer not null,
|
|---|
| 134 | vozac_id integer not null,
|
|---|
| 135 |
|
|---|
| 136 | constraint pk_Ruti primary key (ruta_id),
|
|---|
| 137 | constraint fk_Ruti_Vozila foreign key(vozilo_id) references project.Vozila(vozilo_id),
|
|---|
| 138 | constraint fk_Ruti_Zapocnuva_Gradovi foreign key(zapocnuva_vo) references project.Gradovi(grad_id),
|
|---|
| 139 | constraint fk_Ruti_Zavrsuva_Gradovi foreign key(zavrsuva_vo) references project.Gradovi(grad_id),
|
|---|
| 140 | constraint fk_Ruti_Dispeceri foreign key(dispecer_id) references project.Dispeceri(dispecer_id),
|
|---|
| 141 | constraint fk_Ruti_Vozaci foreign key(vozac_id) references project.Vozaci(vozac_id)
|
|---|
| 142 | );
|
|---|
| 143 |
|
|---|
| 144 | -- Kategorija: Kategorii(kategorija_id, kategorija_ime)
|
|---|
| 145 | create table project.Kategorii(
|
|---|
| 146 | kategorija_id serial not null,
|
|---|
| 147 | kategorija_ime varchar(300) not null,
|
|---|
| 148 |
|
|---|
| 149 | constraint pk_Kategorii primary key (kategorija_id),
|
|---|
| 150 | constraint un_Kategorija_ime unique (kategorija_ime)
|
|---|
| 151 | );
|
|---|
| 152 |
|
|---|
| 153 | -- Roba: Roba(roba_id, roba_kolicina, kategorija_id*(Kategorii))
|
|---|
| 154 | create table project.Roba(
|
|---|
| 155 | roba_id serial not null,
|
|---|
| 156 | roba_kolicina integer not null,
|
|---|
| 157 |
|
|---|
| 158 | kategorija_id integer not null,
|
|---|
| 159 |
|
|---|
| 160 | constraint pk_Roba primary key (roba_id),
|
|---|
| 161 | constraint fk_Roba_Kategorii foreign key(roba_id) references project.Kategorii(kategorija_id)
|
|---|
| 162 | );
|
|---|
| 163 |
|
|---|
| 164 | -- Rezervacii: Rezervacii(rezervacija_id, klient_id*(Klienti), ruta_id*(Ruti), roba_id*(Roba))
|
|---|
| 165 | create table project.Rezervacii(
|
|---|
| 166 | rezervacija_id serial not null,
|
|---|
| 167 |
|
|---|
| 168 | klient_id integer not null,
|
|---|
| 169 | ruta_id integer not null,
|
|---|
| 170 | roba_id integer not null,
|
|---|
| 171 |
|
|---|
| 172 | constraint pk_Rezervacii primary key (rezervacija_id),
|
|---|
| 173 | constraint fk_Rezervacii_Klienti foreign key (klient_id) references project.Klienti(klient_id),
|
|---|
| 174 | constraint fk_Rezervacii_Ruti foreign key (ruta_id) references project.Ruti(ruta_id),
|
|---|
| 175 | constraint fk_Rezervacii_Roba foreign key (roba_id) references project.Roba(roba_id)
|
|---|
| 176 | );
|
|---|
| 177 |
|
|---|
| 178 | -- Fakturi: Fakturi(faktura_id, faktura_iznos, rezervacija_id*(Rezervacii), administrator_id*(Vraboteni))
|
|---|
| 179 | create table project.Fakturi(
|
|---|
| 180 | faktura_id serial not null,
|
|---|
| 181 | faktura_iznos integer not null,
|
|---|
| 182 |
|
|---|
| 183 | rezervacija_id integer not null,
|
|---|
| 184 | administrator_id integer not null,
|
|---|
| 185 |
|
|---|
| 186 | constraint pk_Fakturi primary key (faktura_id),
|
|---|
| 187 | constraint fk_Fakturi_Rezervacii foreign key (rezervacija_id) references project.Rezervacii(rezervacija_id),
|
|---|
| 188 | constraint fk_Fakturi_Administratori foreign key (administrator_id) references project.Administratori(administrator_id)
|
|---|
| 189 | );
|
|---|
| 190 |
|
|---|
| 191 | -- Licenci: Licenci(kompanija_id*(Kompanii), licenca_id, licenca_vazi_od, licenca_vazi_do)
|
|---|
| 192 | create table project.Licenci(
|
|---|
| 193 | licenca_id serial not null,
|
|---|
| 194 | licenca_vazi_od date not null,
|
|---|
| 195 | licenca_vazi_do date not null,
|
|---|
| 196 |
|
|---|
| 197 | kompanija_id integer not null,
|
|---|
| 198 |
|
|---|
| 199 | constraint pk_Licenci primary key (licenca_id),
|
|---|
| 200 | constraint fk_Licenci_Kompanii foreign key (kompanija_id) references project.Kompanii(kompanija_id)
|
|---|
| 201 | );
|
|---|
| 202 |
|
|---|