ALTER TABLE _setup_main ADD COLUMN projektkezeles integer;
ALTER TABLE _setup_main ALTER COLUMN projektkezeles SET STORAGE PLAIN;
ALTER TABLE _setup_main ALTER COLUMN projektkezeles SET DEFAULT 0;

ALTER TABLE raktar_mozgas_fej ADD COLUMN projekt integer;
ALTER TABLE raktar_mozgas_fej ALTER COLUMN projekt SET STORAGE PLAIN;
ALTER TABLE raktar_mozgas_fej ALTER COLUMN projekt SET DEFAULT 0;

CREATE INDEX fki_raktar_mozgas_fej_fk7
  ON raktar_mozgas_fej
  USING btree
  (projekt);

CREATE TABLE projekt_besorolas
(
  kod serial NOT NULL,
  lang_0000040e character varying(30),
  lang_00000409 character varying(30),
  lang_00000407 character varying(30),
  m_userid character varying(20) DEFAULT '',
  m_date date DEFAULT '2005-01-01',
  m_time time without time zone DEFAULT '00:00:00',
  c_userid character varying(20) DEFAULT '',
  c_date date DEFAULT '2005-01-01',
  c_time time without time zone DEFAULT '00:00:00',
  hasznalatban smallint DEFAULT 0,
  CONSTRAINT projekt_besorolas_pky PRIMARY KEY (kod)
) 
WITHOUT OIDS;

CREATE TABLE projekt_statusz
(
  kod serial NOT NULL,
  lang_0000040e character varying(30),
  lang_00000409 character varying(30),
  lang_00000407 character varying(30),
  m_userid character varying(20) DEFAULT '',
  m_date date DEFAULT '2005-01-01',
  m_time time without time zone DEFAULT '00:00:00',
  c_userid character varying(20) DEFAULT '',
  c_date date DEFAULT '2005-01-01',
  c_time time without time zone DEFAULT '00:00:00',
  hasznalatban smallint DEFAULT 0,
  CONSTRAINT projekt_statusz_pkey PRIMARY KEY (kod)
) 
WITHOUT OIDS;

CREATE TABLE projekt_utemezes
(
  kod serial NOT NULL,
  lang_0000040e character varying(30),
  lang_00000409 character varying(30),
  lang_00000407 character varying(30),
  m_userid character varying(20) DEFAULT '',
  m_date date DEFAULT '2005-01-01',
  m_time time without time zone DEFAULT '00:00:00',
  c_userid character varying(20) DEFAULT '',
  c_date date DEFAULT '2005-01-01',
  c_time time without time zone DEFAULT '00:00:00',
  hasznalatban smallint DEFAULT 0,
  CONSTRAINT projekt_utemezes_pkey PRIMARY KEY (kod)
) 
WITHOUT OIDS;

CREATE TABLE projektek
(
  kod serial NOT NULL,
  besorolas integer DEFAULT 0,
  partner_kod integer DEFAULT 0,
  helyszin character varying,
  leiras character varying,
  rogzites date,
  datum1 date,
  datum2 date,
  utemezes integer DEFAULT 0,
  kiadta integer DEFAULT 0,
  vegzi integer DEFAULT 0,
  ellenorzi integer DEFAULT 0,
  megjegyzes character varying,
  m_userid character varying(20) DEFAULT '',
  m_date date DEFAULT '2005-01-01',
  m_time time without time zone DEFAULT '00:00:00',
  c_userid character varying(20) DEFAULT '',
  c_date date DEFAULT '2005-01-01',
  c_time time without time zone DEFAULT '00:00:00',
  hasznalatban smallint DEFAULT 0,
  statusz integer DEFAULT 0,
  CONSTRAINT projektek_pky PRIMARY KEY (kod),
  CONSTRAINT projektek_fk1 FOREIGN KEY (besorolas)
      REFERENCES projekt_besorolas (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT projektek_fk2 FOREIGN KEY (statusz)
      REFERENCES projekt_statusz (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT projektek_fk3 FOREIGN KEY (utemezes)
      REFERENCES projekt_utemezes (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT projektek_fk4 FOREIGN KEY (partner_kod)
      REFERENCES partner (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT projektek_fk5 FOREIGN KEY (kiadta)
      REFERENCES munkatars (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT projektek_fk6 FOREIGN KEY (vegzi)
      REFERENCES munkatars (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT projektek_fk7 FOREIGN KEY (ellenorzi)
      REFERENCES munkatars (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
) 
WITHOUT OIDS;

CREATE INDEX fki_projektek_fk1
  ON projektek
  USING btree
  (besorolas);

CREATE INDEX fki_projektek_fk2
  ON projektek
  USING btree
  (statusz);

CREATE INDEX fki_projektek_fk3
  ON projektek
  USING btree
  (utemezes);

CREATE INDEX fki_projektek_fk4
  ON projektek
  USING btree
  (partner_kod);

CREATE INDEX fki_projektek_fk5
  ON projektek
  USING btree
  (kiadta);

CREATE INDEX fki_projektek_fk6
  ON projektek
  USING btree
  (vegzi);

CREATE INDEX fki_projektek_fk7
  ON projektek
  USING btree
  (ellenorzi);

ALTER TABLE esemeny_naplo ADD COLUMN kapcsolt_dokumentum bytea;
ALTER TABLE esemeny_naplo ALTER COLUMN kapcsolt_dokumentum SET STORAGE EXTENDED;

ALTER TABLE esemeny_naplo ADD COLUMN kapcsolt_dokumentum_tipusa character(3);
ALTER TABLE esemeny_naplo ALTER COLUMN kapcsolt_dokumentum_tipusa SET STORAGE EXTENDED;
ALTER TABLE esemeny_naplo ALTER COLUMN kapcsolt_dokumentum_tipusa SET DEFAULT 'RTF';


ALTER TABLE esemeny_naplo
  ADD CONSTRAINT esemeny_naplo_fk1 FOREIGN KEY (esemeny_kod)
      REFERENCES esemeny (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION;
CREATE INDEX fki_esemeny_naplo_fk1
  ON esemeny_naplo
  USING btree
  (esemeny_kod);

ALTER TABLE esemeny_naplo
  ADD CONSTRAINT esemeny_naplo_fk2 FOREIGN KEY (partner_kod)
      REFERENCES partner (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION;
CREATE INDEX fki_esemeny_naplo_fk2
  ON esemeny_naplo
  USING btree
  (partner_kod);

ALTER TABLE esemeny_naplo
  ADD CONSTRAINT esemeny_naplo_ch1 CHECK (kapcsolt_dokumentum_tipusa = 'RTF' OR kapcsolt_dokumentum_tipusa = 'JPG' OR kapcsolt_dokumentum_tipusa = '   ');

ALTER TABLE raktar_mozgas_fej
  ADD CONSTRAINT raktar_mozgas_fej_fk7 FOREIGN KEY (projekt)
      REFERENCES projektek (kod) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION;

CREATE TABLE korlevel
(
  kod serial NOT NULL,
  nev character(40) DEFAULT '',
  "level" bytea,
  leiras character varying(200) DEFAULT '',
  CONSTRAINT korlevel_pkey PRIMARY KEY (kod)
) 
WITHOUT OIDS;