#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    idriadok SERIAL,
    uzaverka character(17) COLLATE pg_catalog."default",
    c_data smallint NOT NULL DEFAULT 1,
    id_kas character(2) COLLATE pg_catalog."default",
    rep_uzaverka jsonb,
    fuzcislo integer,
    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='sk__uza' and column_name='rep_uzaverka') THEN
			ALTER TABLE <SCHEMA>.sk__uza  ADD COLUMN rep_uzaverka json;
	END IF;

	IF  NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__uza' and column_name='rk_rep') THEN
		ALTER TABLE <SCHEMA>.sk__uza  ADD COLUMN rk_rep text COLLATE pg_catalog."default";
	END IF;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__uza' and column_name='rep_uzaverka') THEN
		ALTER TABLE <SCHEMA>.sk__uza  ADD COLUMN rep_uzaverka jsonb;
	ELSE
		ALTER TABLE <SCHEMA>.sk__uza ALTER COLUMN rep_uzaverka TYPE jsonb ;
	END IF;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__uza' and column_name='fuzcislo') THEN
			ALTER TABLE <SCHEMA>.sk__uza  ADD COLUMN fuzcislo integer;
	END IF;
END IF;

#[ KONEC SOUBORU ]#