#[ ZACATEK SOUBORU ]#

#DEF <SCHEMA>    food600
#DEF <PRIMARYKEY> id_miest
#DEF <TABLENAME> miestnosti

#[ CREATE TABLE ZACATEK ]#
    id_miest SERIAL,
    pozadie bytea,
    miest character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (id_miest)
#[ CREATE TABLE KONEC ]#

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

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='miestnosti' and column_name='miest' and lower(data_type)='integer') THEN
		ALTER TABLE food600.miestnosti DROP COLUMN miest;
		ALTER TABLE food600.miestnosti ADD  COLUMN  miest character(30) NOT NULL DEFAULT ''::bpchar;
	END IF;

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

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

END IF;

#[ KONEC SOUBORU ]#