#[ ZACATEK SOUBORU ]#

#DEF <SCHEMA>    food600
#DEF <PRIMARYKEY> idr
#DEF <TABLENAME> bufferd

#[ CREATE TABLE ZACATEK ]#
    idriadok integer,
    menobuf character(10) COLLATE pg_catalog."default" NOT NULL,
    c_data smallint NOT NULL DEFAULT 1,
    c_stredisk integer NOT NULL DEFAULT 0,
    c_dokl integer NOT NULL DEFAULT 0,
    c_partner integer NOT NULL DEFAULT 0,
    doklad integer NOT NULL DEFAULT 0,
    datum_dokl date DEFAULT ('now'::text)::date,
    operace character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    pz1 character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    pz2 character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    platba character(5) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    trzba1 numeric(20,10) NOT NULL DEFAULT 0,
    trzba2 numeric(20,10) NOT NULL DEFAULT 0,
    trzba3 numeric(20,10) NOT NULL DEFAULT 0,
    trzba4 numeric(20,10) NOT NULL DEFAULT 0,
    splatnost integer NOT NULL DEFAULT 0,
    sleva_abs numeric(20,10) NOT NULL DEFAULT 0,
    sleva_proc numeric(20,10) NOT NULL DEFAULT 0,
    cen_hlad character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    zaloha numeric(20,10) NOT NULL DEFAULT 0,
    halere numeric(20,10) NOT NULL DEFAULT 0,
    provedl character(3) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    kdy timestamp without time zone,
    c_mena smallint NOT NULL DEFAULT 1,
    partner character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    idr SERIAL,
    odlozene smallint NOT NULL DEFAULT 0,
    bufdidr integer NOT NULL DEFAULT 0,
    poznamka character varying(1000) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::character varying,
    typ_pohybu smallint NOT NULL DEFAULT 0,
    kurz numeric(20,10) NOT NULL DEFAULT 1,
    CONSTRAINT bufferd_idr PRIMARY KEY (idr)
#[ CREATE TABLE KONEC ]#

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

DROP INDEX IF EXISTS <SCHEMA>.bufferd_menobuf;
CREATE INDEX bufferd_menobuf
    ON <SCHEMA>.bufferd USING btree
    (menobuf COLLATE pg_catalog."default" ASC NULLS LAST)
    TABLESPACE pg_default;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='bufferd' and column_name='kurz') THEN
			ALTER TABLE <SCHEMA>.bufferd  ADD COLUMN kurz numeric(20,10) NOT NULL DEFAULT 1;
	END IF;

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='bufferd' and column_name='typ_pohybu') THEN
			ALTER TABLE <SCHEMA>.bufferd  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='bufferd' and column_name='uctexport') THEN
		ALTER TABLE IF EXISTS <SCHEMA>.bufferd  ADD COLUMN uctexport smallint NOT NULL DEFAULT 0;
	END IF;

DROP INDEX  IF EXISTS <SCHEMA>.bufferd_menobuf;
CREATE INDEX bufferd_menobuf  ON <SCHEMA>.bufferd
    USING btree  (menobuf COLLATE pg_catalog."default");

END IF;

#[ KONEC SOUBORU ]#