#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    ucet integer NOT NULL DEFAULT 0,
    c_uzaverka integer DEFAULT 0,
    poradi numeric(4,0) NOT NULL DEFAULT 0,
    txt character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    jmeno character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    adresa1 character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    adresa2 character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    adresa3 character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    schvalil character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    akce character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    dic character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    cislo character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hucet character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hpokoj character(6) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hjmeno character(40) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hporad character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hpref character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hid character(12) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    icdph character(20) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    ico character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    c_data smallint NOT NULL DEFAULT 1,
    idriadok SERIAL,
    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__txt_a' and column_name='transaction_metadata') THEN
		ALTER TABLE <SCHEMA>.sk__txt_a  ADD COLUMN transaction_metadata json;
	END IF;

	IF EXISTS ( SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__txt_a' and column_name='hjmeno'  and character_maximum_length < 40 ) THEN
		ALTER TABLE <SCHEMA>.sk__txt_a  ALTER COLUMN hjmeno TYPE character(40) USING left(hjmeno, 40) ;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__txt_a' and column_name='hpokoj') THEN
		ALTER TABLE <SCHEMA>.sk__txt_a   ALTER COLUMN hpokoj TYPE character(8);
	END IF;

END IF;

#[ KONEC SOUBORU ]#