#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    hor_pref character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hor_path character(200) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hor_hotel character(25) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hor_cdx smallint NOT NULL DEFAULT 0,
    idriadok SERIAL,
    hor_ip character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hor_port integer NOT NULL DEFAULT 0,
    hor_meno character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hor_heslo character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hor_kasa character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    CONSTRAINT hores_d_idriadok PRIMARY KEY (idriadok)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;

INSERT INTO <SCHEMA>.hores_d (hor_pref) values ('7') ;
END IF;


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

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

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

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

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

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_pref') THEN
		ALTER TABLE <SCHEMA>.hores_d   ALTER COLUMN hor_pref SET DEFAULT '';
		ALTER TABLE <SCHEMA>.hores_d   ALTER COLUMN hor_pref SET NOT NULL;
	END IF;
	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_path') THEN
		ALTER TABLE <SCHEMA>.hores_d   ALTER COLUMN hor_path SET DEFAULT '';
		ALTER TABLE <SCHEMA>.hores_d   ALTER COLUMN hor_path SET NOT NULL;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_hotel') THEN
		ALTER TABLE <SCHEMA>.hores_d   ALTER COLUMN hor_hotel SET DEFAULT '';
		ALTER TABLE <SCHEMA>.hores_d   ALTER COLUMN hor_hotel SET NOT NULL;
	END IF;

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

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_pref') THEN
		UPDATE <SCHEMA>.hores_d SET hor_pref='' WHERE hor_pref  IS NULL;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_path') THEN
		UPDATE <SCHEMA>.hores_d SET hor_path='' WHERE hor_path  IS NULL;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_hotel') THEN
		UPDATE <SCHEMA>.hores_d SET hor_hotel='' WHERE hor_hotel  IS NULL;
	END IF;

	ALTER TABLE <SCHEMA>.hores_d  ALTER COLUMN hor_pref TYPE character(5) COLLATE pg_catalog."default";
	ALTER TABLE <SCHEMA>.hores_d  ALTER COLUMN hor_ip TYPE character(50) COLLATE pg_catalog."default";


	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='api_meno') THEN
		ALTER TABLE <SCHEMA>.hores_d  ADD COLUMN api_meno character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='api_heslo') THEN
		ALTER TABLE <SCHEMA>.hores_d  ADD COLUMN api_heslo character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar;
	END IF;

	IF  EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='hores_d' and column_name='hor_pref' and character_maximum_length<6) THEN
		ALTER TABLE <SCHEMA>.hores_d ALTER COLUMN hor_pref TYPE character(6) COLLATE pg_catalog."default";
	END IF;


END IF;

#[ KONEC SOUBORU ]#