#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    idriadok SERIAL,
    tab character varying(50) COLLATE pg_catalog."default",
    zmena timestamp with time zone,
    c_data smallint NOT NULL DEFAULT 1,
    spracovane time with time zone,
    foodie_cas timestamp with time zone,
    prebrate timestamp with time zone,
    hodnota numeric(10,2) NOT NULL DEFAULT 0,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='s_zmeny' AND column_name='hodnota')  THEN
		ALTER TABLE <SCHEMA>.s_zmeny ADD COLUMN hodnota 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='s_zmeny' and column_name='spracovane') THEN
		ALTER TABLE <SCHEMA>.s_zmeny ADD COLUMN spracovane time with time zone;
	END IF;

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

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


	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='food600' and table_name='s_zmeny' and column_name='spracovane') THEN
		ALTER TABLE food600.s_zmeny ADD COLUMN spracovane time with time zone;
	END IF;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='food600' and table_name='s_zmeny' and column_name='zmena') THEN
		ALTER TABLE food600.s_zmeny ADD COLUMN zmena time with time zone;
	ELSE
		ALTER TABLE food600.s_zmeny ALTER COLUMN zmena TYPE timestamp with time zone;
	END IF;



END IF;

#[ KONEC SOUBORU ]#