/* Database generated with pgModeler (PostgreSQL Database Modeler).
  Project Site: pgmodeler.com.br
  Model Author: --- */

SET check_function_bodies = false;
-- ddl-end --


/* Database creation must be done outside an multicommand file.
   These commands were put in this file only for convenience.

-- object: new_database | type: DATABASE -- 
CREATE DATABASE new_database
	ENCODING = 'UTF8'
;
-- ddl-end --


*/

-- object: public.drzave | type: TABLE -- 
CREATE TABLE public.drzave(
	id serial,
	drzava character varying,
	skr2 character(2),
	skr3 character(3),
	unio_datum timestamp DEFAULT =Now(),
	unio_id integer,
	aktivno boolean DEFAULT true,
	orginal_id integer,
	izmjenio_datum timestamp,
	izmjenio_id integer,
	CONSTRAINT pk PRIMARY KEY (id)
)
WITH (OIDS=TRUE);
-- ddl-end --

-- ddl-end --

-- object: public.mjesta | type: TABLE -- 
CREATE TABLE public.mjesta(
	id serial,
	mjesto character varying,
	skr character(3),
	drzava_id integer,
	unio_datum timestamp DEFAULT =Now(),
	unio_id integer,
	aktivno boolean DEFAULT true,
	orginal_id integer,
	izmjenio_datum timestamp,
	izmjenio_id integer,
	CONSTRAINT pk PRIMARY KEY (id)
)
WITH (OIDS=TRUE);
-- ddl-end --

-- ddl-end --

-- object: public.prijave | type: TABLE -- 
CREATE TABLE public.prijave(
	id serial,
	korisnik_id integer,
	prijava timestamp,
	uspjesno boolean,
	odjava timestamp,
	pc_adresa cidr,
	pc_naziv character varying,
	CONSTRAINT pk PRIMARY KEY (id)
)
WITH (OIDS=TRUE);
-- ddl-end --

-- ddl-end --

-- object: public.korisnici | type: TABLE -- 
CREATE TABLE public.korisnici(
	id serial,
	korisnik character varying(20),
	email character varying(50),
	prezime character varying(30),
	ime character varying(20),
	ovlastenje_id integer,
	unio_datum timestamp DEFAULT =Now(),
	unio_id integer,
	aktivno boolean DEFAULT true,
	orginal_id integer,
	izmjenio_datum timestamp,
	izmjenio_id integer,
	CONSTRAINT pk PRIMARY KEY (id)
)
WITH (OIDS=TRUE);
-- ddl-end --

-- ddl-end --

-- object: public.ovlastenja | type: TABLE -- 
CREATE TABLE public.ovlastenja(
	id serial,
	ovlastenje character varying(20),
	CONSTRAINT pk PRIMARY KEY (id)
)
WITH (OIDS=TRUE);
-- ddl-end --

-- ddl-end --

-- object: fk_izmjenio | type: CONSTRAINT -- 
ALTER TABLE public.korisnici ADD CONSTRAINT fk_izmjenio FOREIGN KEY (izmjenio_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_unio | type: CONSTRAINT -- 
ALTER TABLE public.korisnici ADD CONSTRAINT fk_unio FOREIGN KEY (unio_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_orginal | type: CONSTRAINT -- 
ALTER TABLE public.korisnici ADD CONSTRAINT fk_orginal FOREIGN KEY (orginal_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_ovlastenje | type: CONSTRAINT -- 
ALTER TABLE public.korisnici ADD CONSTRAINT fk_ovlastenje FOREIGN KEY (ovlastenje_id)
REFERENCES public.ovlastenja (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_korisnik | type: CONSTRAINT -- 
ALTER TABLE public.prijave ADD CONSTRAINT fk_korisnik FOREIGN KEY (korisnik_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_izmjenio | type: CONSTRAINT -- 
ALTER TABLE public.mjesta ADD CONSTRAINT fk_izmjenio FOREIGN KEY (izmjenio_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_unio | type: CONSTRAINT -- 
ALTER TABLE public.mjesta ADD CONSTRAINT fk_unio FOREIGN KEY (unio_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_drzava | type: CONSTRAINT -- 
ALTER TABLE public.mjesta ADD CONSTRAINT fk_drzava FOREIGN KEY (drzava_id)
REFERENCES public.drzave (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_orginal | type: CONSTRAINT -- 
ALTER TABLE public.mjesta ADD CONSTRAINT fk_orginal FOREIGN KEY (orginal_id)
REFERENCES public.mjesta (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_izmjenio | type: CONSTRAINT -- 
ALTER TABLE public.drzave ADD CONSTRAINT fk_izmjenio FOREIGN KEY (izmjenio_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_unio | type: CONSTRAINT -- 
ALTER TABLE public.drzave ADD CONSTRAINT fk_unio FOREIGN KEY (unio_id)
REFERENCES public.korisnici (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --


-- object: fk_orginal | type: CONSTRAINT -- 
ALTER TABLE public.drzave ADD CONSTRAINT fk_orginal FOREIGN KEY (orginal_id)
REFERENCES public.drzave (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE;
-- ddl-end --



