#[ ZACATEK SOUBORU ]#

#DEF <SCHEMA>    food600
#DEF <PRIMARYKEY> id_limit
#DEF <TABLENAME> nlimit_hl

#[ CREATE TABLE ZACATEK ]#
    id_limit SERIAL,
    menolimit character(50) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    id_typ integer NOT NULL DEFAULT 0,
    is_kasy smallint NOT NULL DEFAULT 0,
    txt_kasy character(20) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    c_kasy integer NOT NULL DEFAULT 0,
    hladina character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    txt1 character(70) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    txt2 character(70) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hladina1 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hladina2 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    zlava numeric(10,2) NOT NULL DEFAULT 0,
    typ_zlavy character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    poznamka text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::character varying,
    pozn_int text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::character varying,
    c_mena smallint NOT NULL DEFAULT 1,
    archiv smallint NOT NULL DEFAULT 0,
    c_data smallint NOT NULL DEFAULT 1,
    zmazane smallint NOT NULL DEFAULT 0,
    kontakt character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    kontakt1 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    prichod character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    firma character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    c_partner integer NOT NULL DEFAULT 0,
    adr1 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    adr2 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    adr3 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    adr4 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    id_stat integer NOT NULL DEFAULT 0,
    typ_pohybu smallint NOT NULL DEFAULT 0,
    CONSTRAINT nlimit_hl_<PRIMARYKEY> PRIMARY KEY (id_limit)
#[ CREATE TABLE KONEC ]#

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

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

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

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

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

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

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

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='nlimit_hl' and column_name='poznamka') THEN
		ALTER TABLE <SCHEMA>.nlimit_hl  ALTER COLUMN poznamka TYPE text;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='nlimit_hl' and column_name='pozn_int') THEN
		ALTER TABLE <SCHEMA>.nlimit_hl  ALTER COLUMN pozn_int TYPE text;
	END IF;

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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='nlimit_hl' and column_name='id_limit_master') THEN
		ALTER TABLE <SCHEMA>.nlimit_hl  ADD COLUMN id_limit_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='nlimit_hl' and column_name='id_sync') THEN
		ALTER TABLE <SCHEMA>.nlimit_hl  ADD COLUMN id_sync integer NOT NULL DEFAULT 0;
	END IF;

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

END IF;

#[ KONEC SOUBORU ]#