#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    idriadok serial,
    ip character varying(255) COLLATE pg_catalog."default",
    port character varying(20) COLLATE pg_catalog."default",
    databaza character varying(255) COLLATE pg_catalog."default",
    meno character varying(255) COLLATE pg_catalog."default",
    heslo character varying(255) COLLATE pg_catalog."default",
    id_local integer NOT NULL DEFAULT 0,
    id_remote integer NOT NULL DEFAULT 0,
    id_local_insert integer NOT NULL DEFAULT 0,
    id_remote_insert integer NOT NULL DEFAULT 0,
    tosomja smallint NOT NULL DEFAULT 0,
    id_master smallint NOT NULL DEFAULT 0,
    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='sync_set' and column_name='id_local_insert_hkredobr') THEN
		alter table <SCHEMA>.sync_set add column id_local_insert_hkredobr integer NOT NULL DEFAULT 0;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sync_set' and column_name='id_local_update_hkredobr') THEN
		alter table <SCHEMA>.sync_set add column id_local_update_hkredobr integer NOT NULL DEFAULT 0;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sync_set' and column_name='id_local_delete_hkredobr') THEN
		alter table <SCHEMA>.sync_set add column id_local_delete_hkredobr integer NOT NULL DEFAULT 0;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sync_set' and column_name='id_remote_insert_hkredobr') THEN
		alter table <SCHEMA>.sync_set add column id_remote_insert_hkredobr integer NOT NULL DEFAULT 0;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sync_set' and column_name='id_remote_update_hkredobr') THEN
		alter table <SCHEMA>.sync_set add column id_remote_update_hkredobr integer NOT NULL DEFAULT 0;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sync_set' and column_name='id_remote_delete_hkredobr') THEN
		alter table <SCHEMA>.sync_set add column id_remote_delete_hkredobr integer NOT NULL DEFAULT 0;
	END IF;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sync_set' and column_name='hotel') THEN
		ALTER TABLE <SCHEMA>.sync_set  ADD COLUMN hotel character varying(100) COLLATE pg_catalog."default";
	END IF;

END IF;

#[ KONEC SOUBORU ]#