#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    ucet integer,
    c_uzaverka integer,
    fucis integer,
    fuciarkod character(20) COLLATE pg_catalog."default",
    fuzcislo integer,
    fuzdate date,
    idriadok SERIAL,
    c_data smallint NOT NULL DEFAULT 1,
    nedokonceny smallint NOT NULL DEFAULT 0,
    prn_no character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    okp character(45) COLLATE pg_catalog."default",
    uid character(50) 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='sk__fis_a' and column_name='okp') THEN
		ALTER TABLE <SCHEMA>.sk__fis_a ALTER COLUMN okp TYPE character (45) COLLATE pg_catalog."default";
		ALTER TABLE <SCHEMA>.sk__fis_a ALTER COLUMN okp DROP NOT NULL;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='uid') THEN
		ALTER TABLE <SCHEMA>.sk__fis_a ALTER COLUMN uid TYPE character (50) COLLATE pg_catalog."default";
		ALTER TABLE <SCHEMA>.sk__fis_a ALTER COLUMN uid DROP NOT NULL;
	END IF;


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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='prn_no') THEN
		ALTER TABLE <SCHEMA>.sk__fis_a  ADD COLUMN prn_no CHARACTER(2) NOT NULL  DEFAULT ''::BPCHAR;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='okp') THEN
		ALTER TABLE <SCHEMA>.sk__fis_a  ADD COLUMN okp CHARACTER(45)  NOT NULL  DEFAULT ''::BPCHAR;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='uid') THEN
		ALTER TABLE <SCHEMA>.sk__fis_a  ADD COLUMN uid CHARACTER(50)  NOT NULL  DEFAULT ''::BPCHAR;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='okp' and column_default is not null) THEN
		ALTER TABLE IF EXISTS <SCHEMA>.sk__fis_a ALTER COLUMN okp DROP DEFAULT;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='uid' and column_default is not null) THEN
		ALTER TABLE IF EXISTS <SCHEMA>.sk__fis_a ALTER COLUMN uid DROP DEFAULT;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='okp' and is_nullable='NO') THEN
		ALTER TABLE IF EXISTS <SCHEMA>.sk__fis_a ALTER COLUMN okp DROP NOT NULL;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk__fis_a' and column_name='uid' and is_nullable='NO') THEN
		ALTER TABLE IF EXISTS <SCHEMA>.sk__fis_a ALTER COLUMN uid DROP NOT NULL;
	END IF;

 END IF;

#[ KONEC SOUBORU ]#