#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    idriadok SERIAL,
    kluc character varying(50) COLLATE pg_catalog."default",
    hodnota character varying(500) COLLATE pg_catalog."default",
    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='texty' and column_name='lhodnota') THEN
		ALTER TABLE <SCHEMA>.texty ADD COLUMN lhodnota text;
	END IF;

	IF  EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='texty' and column_name='c_stredisk') THEN
		ALTER TABLE <SCHEMA>.texty DROP COLUMN c_stredisk ;
	END IF;

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

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

	ALTER TABLE <SCHEMA>.texty DROP CONSTRAINT IF EXISTS uk_texty_kluc;
	ALTER TABLE  <SCHEMA>.texty ADD   CONSTRAINT uk_texty_kluc unique (modul, kluc, c_data) ;

END IF;

#[ KONEC SOUBORU ]#