1 | CREATE SCHEMA IF NOT EXISTS final_eglas;
|
---|
2 |
|
---|
3 | SET SEARCH_PATH TO final_eglas;
|
---|
4 |
|
---|
5 |
|
---|
6 | DROP TABLE IF EXISTS kodovi;
|
---|
7 | DROP TABLE IF EXISTS oformuva;
|
---|
8 | DROP TABLE IF EXISTS se_clenovi_na;
|
---|
9 | DROP TABLE IF EXISTS e_kandidat_vo;
|
---|
10 | DROP TABLE IF EXISTS glasovi_za_lista;
|
---|
11 | DROP TABLE IF EXISTS glasovi_za_kandidat;
|
---|
12 | DROP TABLE IF EXISTS glasanja;
|
---|
13 | DROP TABLE IF EXISTS komisii;
|
---|
14 | DROP TABLE IF EXISTS kandidatski_listi;
|
---|
15 | DROP TABLE IF EXISTS kandidaturi;
|
---|
16 | DROP TABLE IF EXISTS realizacii_so_kandidaturi;
|
---|
17 | DROP TABLE IF EXISTS realizacii_so_kandidatska_lista;
|
---|
18 | DROP TABLE IF EXISTS koalicii;
|
---|
19 | DROP TABLE IF EXISTS prigovori_od_gragjani;
|
---|
20 | DROP TABLE IF EXISTS prigovori_od_kandidati;
|
---|
21 | DROP TABLE IF EXISTS prigovori;
|
---|
22 | DROP TABLE IF EXISTS partii;
|
---|
23 | DROP TABLE IF EXISTS realizacii_na_izbori;
|
---|
24 | DROP TABLE IF EXISTS clenovi_na_komisija;
|
---|
25 | DROP TABLE IF EXISTS kandidati;
|
---|
26 | DROP TABLE IF EXISTS lokacija_izbiracko_mesto;
|
---|
27 | DROP TABLE IF EXISTS korisnicki_profil;
|
---|
28 | DROP TABLE IF EXISTS dokumenti_za_identifikacija;
|
---|
29 | DROP TABLE IF EXISTS gragjani;
|
---|
30 | DROP TABLE IF EXISTS adresi;
|
---|
31 | DROP TABLE IF EXISTS kandidatski_listi;
|
---|
32 | DROP TABLE IF EXISTS izbiracki_mesta;
|
---|
33 | DROP TABLE IF EXISTS izborni_edinici;
|
---|
34 | DROP TABLE IF EXISTS izbori;
|
---|
35 | DROP TABLE IF EXISTS opstini;
|
---|
36 |
|
---|
37 | CREATE TABLE opstini (
|
---|
38 | o_id SERIAL PRIMARY KEY,
|
---|
39 | o_ime VARCHAR(255) NOT NULL
|
---|
40 | );
|
---|
41 |
|
---|
42 | CREATE TABLE izbori (
|
---|
43 | i_id SERIAL PRIMARY KEY,
|
---|
44 | i_naziv VARCHAR(255) NOT NULL
|
---|
45 | );
|
---|
46 |
|
---|
47 | CREATE TABLE izborni_edinici (
|
---|
48 | ie_id SERIAL PRIMARY KEY,
|
---|
49 | ie_ime VARCHAR(255) NOT NULL,
|
---|
50 | ie_broj_pratenici INT NOT NULL
|
---|
51 | );
|
---|
52 |
|
---|
53 | CREATE TABLE izbiracki_mesta (
|
---|
54 | im_id SERIAL PRIMARY KEY,
|
---|
55 | im_mesto VARCHAR(255) NOT NULL,
|
---|
56 | ie_id INT NOT NULL,
|
---|
57 | a_id BIGINT NOT NULL,
|
---|
58 |
|
---|
59 | CONSTRAINT fk_izbiracki_mesta_izborni_edinici FOREIGN KEY (ie_id) REFERENCES izborni_edinici(ie_id)
|
---|
60 | );
|
---|
61 |
|
---|
62 | CREATE TABLE adresi (
|
---|
63 | a_id BIGSERIAL PRIMARY KEY,
|
---|
64 | a_ulica VARCHAR(255) NOT NULL,
|
---|
65 | a_broj INT NOT NULL,
|
---|
66 | a_vlez VARCHAR(255),
|
---|
67 | a_stan VARCHAR(255),
|
---|
68 | o_id INT NOT NULL,
|
---|
69 | im_id INT,
|
---|
70 | CONSTRAINT fk_adresi_opstini FOREIGN KEY (o_id) REFERENCES opstini(o_id),
|
---|
71 | CONSTRAINT fk_adresi_izbiracki_mesta FOREIGN KEY (a_id) REFERENCES izbiracki_mesta(im_id)
|
---|
72 | );
|
---|
73 |
|
---|
74 | CREATE TABLE gragjani (
|
---|
75 | g_id BIGSERIAL PRIMARY KEY,
|
---|
76 | g_ime VARCHAR(255) NOT NULL,
|
---|
77 | g_prezime VARCHAR(255) NOT NULL,
|
---|
78 | g_embg VARCHAR(13) NOT NULL,
|
---|
79 | g_datum_ragjanje DATE NOT NULL,
|
---|
80 | g_godini INT NOT NULL,
|
---|
81 | a_id BIGINT NOT NULL,
|
---|
82 | CONSTRAINT fk_gragjani_adresi FOREIGN KEY (a_id) REFERENCES adresi(a_id)
|
---|
83 | );
|
---|
84 |
|
---|
85 | CREATE TABLE korisnicki_profil (
|
---|
86 | kp_id BIGSERIAL PRIMARY KEY,
|
---|
87 | kp_korisnicko_ime VARCHAR(255) NOT NULL,
|
---|
88 | kp_lozinka VARCHAR(255) NOT NULL,
|
---|
89 | kp_uloga VARCHAR(255) NOT NULL,
|
---|
90 | g_id BIGINT NOT NULL,
|
---|
91 | CONSTRAINT fk_profili_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id)
|
---|
92 | );
|
---|
93 |
|
---|
94 |
|
---|
95 | CREATE TABLE dokumenti_za_identifikacija (
|
---|
96 | d_broj BIGSERIAL PRIMARY KEY,
|
---|
97 | d_vazhi_od DATE NOT NULL,
|
---|
98 | d_vazhi_do DATE NOT NULL,
|
---|
99 | d_izdaden DATE NOT NULL,
|
---|
100 | g_id BIGINT NOT NULL,
|
---|
101 | CONSTRAINT fk_dokumenti_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id)
|
---|
102 | );
|
---|
103 |
|
---|
104 | CREATE TABLE kandidati (
|
---|
105 | g_id BIGSERIAL PRIMARY KEY,
|
---|
106 | CONSTRAINT fk_kandidati_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id)
|
---|
107 | );
|
---|
108 |
|
---|
109 | CREATE TABLE clenovi_na_komisija (
|
---|
110 | g_id BIGSERIAL PRIMARY KEY,
|
---|
111 | CONSTRAINT fk_clenovi_na_komisija_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id)
|
---|
112 | );
|
---|
113 |
|
---|
114 | CREATE TABLE realizacii_na_izbori (
|
---|
115 | ri_id SERIAL PRIMARY KEY,
|
---|
116 | ri_ime VARCHAR(255) NOT NULL,
|
---|
117 | ri_datum DATE NOT NULL,
|
---|
118 | i_id SERIAL NOT NULL,
|
---|
119 | CONSTRAINT fk_realizacii_na_izbori_izbori FOREIGN KEY (i_id) REFERENCES izbori(i_id)
|
---|
120 | );
|
---|
121 |
|
---|
122 | CREATE TABLE partii (
|
---|
123 | p_id SERIAL PRIMARY KEY,
|
---|
124 | p_ime VARCHAR(255) NOT NULL,
|
---|
125 | a_id BIGINT NOT NULL,
|
---|
126 | CONSTRAINT fk_partii_adresi FOREIGN KEY (a_id) REFERENCES adresi(a_id)
|
---|
127 | );
|
---|
128 |
|
---|
129 | CREATE TABLE prigovori (
|
---|
130 | pr_id SERIAL PRIMARY KEY,
|
---|
131 | pr_opis VARCHAR(255) NOT NULL,
|
---|
132 | ri_id INT NOT NULL,
|
---|
133 | im_id INT NOT NULL,
|
---|
134 | CONSTRAINT fk_prigovori_realizacii_na_izbori FOREIGN KEY (ri_id) REFERENCES realizacii_na_izbori(ri_id),
|
---|
135 | CONSTRAINT fk_prigovori_izbiracki_mesta FOREIGN KEY (im_id) REFERENCES izbiracki_mesta(im_id)
|
---|
136 | );
|
---|
137 |
|
---|
138 | CREATE TABLE prigovori_od_kandidati (
|
---|
139 | pr_id SERIAL PRIMARY KEY,
|
---|
140 | g_id BIGINT NOT NULL,
|
---|
141 | CONSTRAINT fk_prigovori_gragjani_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id),
|
---|
142 | CONSTRAINT fk_prigovori_gragjani_prigovori FOREIGN KEY (pr_id) REFERENCES prigovori(pr_id)
|
---|
143 | );
|
---|
144 |
|
---|
145 | CREATE TABLE prigovori_od_gragjani (
|
---|
146 | pr_id SERIAL PRIMARY KEY,
|
---|
147 | g_id BIGINT NOT NULL,
|
---|
148 | CONSTRAINT fk_prigovori_gragjani_kandidati FOREIGN KEY (g_id) REFERENCES kandidati(g_id),
|
---|
149 | CONSTRAINT fk_prigovori_gragjani_prigovori FOREIGN KEY (pr_id) REFERENCES prigovori(pr_id)
|
---|
150 | );
|
---|
151 |
|
---|
152 | CREATE TABLE koalicii (
|
---|
153 | koa_id SERIAL PRIMARY KEY,
|
---|
154 | koa_ime VARCHAR(255) NOT NULL,
|
---|
155 | koa_moto VARCHAR(255) NOT NULL,
|
---|
156 | ri_id INT NOT NULL,
|
---|
157 | o_id INT,
|
---|
158 | ie_id INT,
|
---|
159 | CONSTRAINT fk_koalicii_realizacii_na_izbori FOREIGN KEY (ri_id) REFERENCES realizacii_na_izbori(ri_id),
|
---|
160 | CONSTRAINT fk_koalicii_opstini FOREIGN KEY (o_id) REFERENCES opstini(o_id),
|
---|
161 | CONSTRAINT fk_koalicii_izborni_edinici FOREIGN KEY (ie_id) REFERENCES izborni_edinici(ie_id)
|
---|
162 | );
|
---|
163 |
|
---|
164 | CREATE TABLE realizacii_so_kandidatska_lista (
|
---|
165 | ri_id SERIAL PRIMARY KEY,
|
---|
166 | CONSTRAINT fk_realizacii_so_kandidatska_lista_realizacii_na_izbori FOREIGN KEY (ri_id) REFERENCES realizacii_na_izbori(ri_id)
|
---|
167 | );
|
---|
168 |
|
---|
169 | CREATE TABLE realizacii_so_kandidaturi (
|
---|
170 | ri_id SERIAL PRIMARY KEY,
|
---|
171 | CONSTRAINT fk_realizacii_so_kandidaturi_realizacii_na_izbori FOREIGN KEY (ri_id) REFERENCES realizacii_na_izbori(ri_id)
|
---|
172 | );
|
---|
173 |
|
---|
174 | CREATE TABLE kandidaturi (
|
---|
175 | kan_id SERIAL PRIMARY KEY,
|
---|
176 | kan_opis VARCHAR(255) NOT NULL,
|
---|
177 | g_id BIGINT NOT NULL,
|
---|
178 | ri_id INT NOT NULL,
|
---|
179 | p_id INT,
|
---|
180 | o_id INT,
|
---|
181 | CONSTRAINT fk_kandidaturi_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id),
|
---|
182 | CONSTRAINT fk_kandidaturi_realizacii_so_kandidat FOREIGN KEY (ri_id) REFERENCES realizacii_so_kandidaturi(ri_id),
|
---|
183 | CONSTRAINT fk_kandidaturi_partii FOREIGN KEY (p_id) REFERENCES partii(p_id),
|
---|
184 | CONSTRAINT fk_kandidaturi_opstini FOREIGN KEY (o_id) REFERENCES opstini(o_id)
|
---|
185 | );
|
---|
186 |
|
---|
187 | CREATE TABLE kandidatski_listi (
|
---|
188 | kl_id SERIAL PRIMARY KEY,
|
---|
189 | kl_opis VARCHAR(255) NOT NULL,
|
---|
190 | ri_id INT NOT NULL,
|
---|
191 | p_id INT,
|
---|
192 | ie_id INT NOT NULL,
|
---|
193 | CONSTRAINT fk_kandidatski_listi_realizacii_so_kandidatska_lista FOREIGN KEY (ri_id) REFERENCES realizacii_so_kandidatska_lista(ri_id),
|
---|
194 | CONSTRAINT fk_kandidatski_listi_partii FOREIGN KEY (p_id) REFERENCES partii(p_id),
|
---|
195 | CONSTRAINT fk_kandidatski_listi_izborni_edinici FOREIGN KEY (ie_id) REFERENCES izborni_edinici(ie_id)
|
---|
196 | );
|
---|
197 |
|
---|
198 | CREATE TABLE komisii (
|
---|
199 | kom_id SERIAL PRIMARY KEY,
|
---|
200 | ri_id INT NOT NULL,
|
---|
201 | im_id INT NOT NULL,
|
---|
202 | CONSTRAINT fk_komisii_realizacii_na_izbori FOREIGN KEY (ri_id) REFERENCES realizacii_na_izbori(ri_id),
|
---|
203 | CONSTRAINT fk_komisii_izbiracki_mesta FOREIGN KEY (im_id) REFERENCES izbiracki_mesta(im_id)
|
---|
204 | );
|
---|
205 |
|
---|
206 | CREATE TABLE glasanja (
|
---|
207 | ug_id SERIAL PRIMARY KEY,
|
---|
208 | ug_vreme TIMESTAMP NOT NULL,
|
---|
209 | g_id BIGINT NOT NULL,
|
---|
210 | im_id INT NOT NULL,
|
---|
211 | ri_id INT NOT NULL,
|
---|
212 | CONSTRAINT fk_glasanja_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id),
|
---|
213 | CONSTRAINT fk_glasanja_izbiracki_mesta FOREIGN KEY (im_id) REFERENCES izbiracki_mesta(im_id),
|
---|
214 | CONSTRAINT fk_glasanja_realizacii_na_izbori FOREIGN KEY (ri_id) REFERENCES realizacii_na_izbori(ri_id)
|
---|
215 | );
|
---|
216 |
|
---|
217 | CREATE TABLE glasovi_za_kandidat (
|
---|
218 | gk_id BIGSERIAL PRIMARY KEY,
|
---|
219 | im_id INT NOT NULL,
|
---|
220 | ri_id INT NOT NULL,
|
---|
221 | kan_id INT NOT NULL,
|
---|
222 | CONSTRAINT fk_glas_za_kandidat_izbiracki_mesta FOREIGN KEY (im_id) REFERENCES izbiracki_mesta(im_id),
|
---|
223 | CONSTRAINT fk_glas_za_kandidat_realizacii_so_kandidate FOREIGN KEY (ri_id) REFERENCES realizacii_so_kandidaturi(ri_id),
|
---|
224 | CONSTRAINT fk_glas_za_kandidat_kandidaturi FOREIGN KEY (kan_id) REFERENCES kandidaturi(kan_id)
|
---|
225 | );
|
---|
226 |
|
---|
227 | CREATE TABLE glasovi_za_lista (
|
---|
228 | gl_id BIGSERIAL PRIMARY KEY,
|
---|
229 | im_id INT NOT NULL,
|
---|
230 | ri_id INT NOT NULL,
|
---|
231 | kl_id INT NOT NULL,
|
---|
232 | CONSTRAINT fk_glas_za_kandidat_izbiracki_mesta FOREIGN KEY (im_id) REFERENCES izbiracki_mesta(im_id),
|
---|
233 | CONSTRAINT fk_glas_za_kandidat_realizacii_so_kandidate FOREIGN KEY (ri_id) REFERENCES realizacii_so_kandidaturi(ri_id),
|
---|
234 | CONSTRAINT fk_glas_za_lista_kandidatski_listi FOREIGN KEY (kl_id) REFERENCES realizacii_so_kandidatska_lista(ri_id)
|
---|
235 | );
|
---|
236 |
|
---|
237 | CREATE TABLE e_kandidat_vo (
|
---|
238 | g_id BIGSERIAL NOT NULL,
|
---|
239 | kl_id INT NOT NULL,
|
---|
240 | PRIMARY KEY (g_id, kl_id),
|
---|
241 | CONSTRAINT fk_e_kandidat_vo_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id),
|
---|
242 | CONSTRAINT fk_e_kandidat_vo_kandidatski_listi FOREIGN KEY (kl_id) REFERENCES kandidatski_listi(kl_id)
|
---|
243 | );
|
---|
244 |
|
---|
245 | CREATE TABLE se_clenovi_na (
|
---|
246 | g_id BIGSERIAL NOT NULL,
|
---|
247 | kom_id INT NOT NULL,
|
---|
248 | PRIMARY KEY (g_id, kom_id),
|
---|
249 | CONSTRAINT fk_se_clenovi_na_gragjani FOREIGN KEY (g_id) REFERENCES gragjani(g_id),
|
---|
250 | CONSTRAINT fk_se_clenovi_na_komisii FOREIGN KEY (kom_id) REFERENCES komisii(kom_id)
|
---|
251 | );
|
---|
252 |
|
---|
253 | CREATE TABLE oformuva(
|
---|
254 | p_id SERIAL NOT NULL,
|
---|
255 | koa_id SERIAL NOT NULL,
|
---|
256 | PRIMARY KEY (p_id, koa_id),
|
---|
257 | CONSTRAINT fk_oformuva_partii FOREIGN KEY (p_id) REFERENCES partii(p_id),
|
---|
258 | CONSTRAINT fk_oformuva_koalicii FOREIGN KEY (koa_id) REFERENCES koalicii(koa_id)
|
---|
259 | );
|
---|
260 |
|
---|
261 | CREATE TABLE kodovi(
|
---|
262 | ug_id SERIAL NOT NULL,
|
---|
263 | kod_kod VARCHAR(255) NOT NULL UNIQUE,
|
---|
264 | kod_vazi_do DATE NOT NULL,
|
---|
265 | PRIMARY KEY(kod_kod, ug_id),
|
---|
266 | CONSTRAINT fk_kodovi_glasanja FOREIGN KEY (ug_id) REFERENCES glasanja(ug_id)
|
---|
267 | );
|
---|