#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    idriadok SERIAL,
    id_karty integer NOT NULL DEFAULT 0,
    id_ucet integer NOT NULL DEFAULT 0,
    id_limit integer NOT NULL DEFAULT 0,
    id_den integer NOT NULL DEFAULT 0,
    id_rov integer NOT NULL DEFAULT 0,
    dieta character(5) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    skupina character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    poradie character(4) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    pocet numeric(3,0) NOT NULL DEFAULT 0,
    prenesene smallint NOT NULL DEFAULT 0,
    vydane smallint NOT NULL DEFAULT 0,
    dat_vyd timestamp with time zone,
    dat_obj timestamp with time zone,
    dat_pren timestamp with time zone,
    cena numeric(10,2) NOT NULL DEFAULT 0,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (idriadok)
#[ CREATE TABLE KONEC ]#

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

IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='obj_stravy' and column_name='cena') THEN
	ALTER TABLE <SCHEMA>.obj_stravy  ADD COLUMN cena numeric(10, 2) NOT NULL DEFAULT 0;
END IF;

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

IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='obj_stravy' and column_name='dat_vyd') THEN
	ALTER TABLE <SCHEMA>.obj_stravy   ADD COLUMN dat_vyd timestamp with time zone; 
END IF;

IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='obj_stravy' and column_name='dat_obj') THEN
	ALTER TABLE <SCHEMA>.obj_stravy   ADD COLUMN dat_obj timestamp with time zone;
END IF;

IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='obj_stravy' and column_name='dat_pren') THEN
	ALTER TABLE <SCHEMA>.obj_stravy   ADD COLUMN dat_pren timestamp with time zone;
END IF;

END IF;

#[ KONEC SOUBORU ]#