#[ ZACATEK SOUBORU ]#

#DEF <SCHEMA>    food600
#DEF <PRIMARYKEY> idriadok
#DEF <TABLENAME> typypohybov

#[ CREATE TABLE ZACATEK ]#
    idriadok SERIAL,
    typ_zakladny character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    meno character varying(50) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::character varying,
    typ_partner smallint NOT NULL DEFAULT 0,
    c_partner integer NOT NULL DEFAULT 0,
    typ_ceny smallint NOT NULL DEFAULT 0,
    poradie smallint NOT NULL DEFAULT 0,
    id_typ smallint NOT NULL DEFAULT 0,
    zmazane smallint NOT NULL DEFAULT 0,
    typ_spotreby smallint NOT NULL DEFAULT 0,
    cen_hlad character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    id_kas character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

#[ IF EXIST ZACATEK ]#
#[ PRIMARYKEY ]#

COMMENT ON COLUMN <SCHEMA>.typypohybov.typ_partner
    IS '0 - vyber z partnerov pouzitelnych pre dany typ_zakladny
1 - pevne definovany partner (uvedie sa v stlpci c_partner)
2 - namiesto c_partner pouzit cislo strediska, na ktorom sa pohyb robi';

COMMENT ON COLUMN <SCHEMA>.typypohybov.typ_ceny
    IS '0 - stale pouzit aktualnu priemernu cenu
1 - ak ide o prijem pouzit aktualnu priemernu cenu. Ak by bolo nulova pytat sa na cenu, ak prihlaseny pouzivatel ma na to pravo. Inak sa karta neda pouzit.
2 - ak ide o prijem volna cena - zada pouzivatel
';

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='typypohybov' and column_name='typ_spotreby') THEN
			ALTER TABLE <SCHEMA>.typypohybov  ADD COLUMN typ_spotreby smallint NOT NULL DEFAULT 0;
	END IF;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='typypohybov' and column_name='cen_hlad') THEN
			ALTER TABLE <SCHEMA>.typypohybov  ADD COLUMN cen_hlad character(2) NOT NULL DEFAULT '';
	END IF;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='typypohybov' and column_name='id_kas') THEN
			ALTER TABLE <SCHEMA>.typypohybov  ADD COLUMN id_kas character(2) NOT NULL DEFAULT '';
	END IF;

END IF;

#[ KONEC SOUBORU ]#