#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    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 NOT NULL DEFAULT clock_timestamp(),
    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),
    splatnost numeric(20,10) 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,
    uctsuma numeric(20,10) NOT NULL DEFAULT (0),
    c_mena smallint NOT NULL DEFAULT 1,
    kdy timestamp without time zone,
    c_data smallint NOT NULL DEFAULT 1,
    idriadok SERIAL,
    uctexport smallint NOT NULL DEFAULT 0,
    poznamka character varying(1000) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::character varying,
    typ_pohybu smallint NOT NULL DEFAULT 0,
    c_dokl_x integer NOT NULL DEFAULT 0,
    kurz numeric(20,10) NOT NULL DEFAULT 1,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (idriadok)
#[ CREATE TABLE KONEC ]#

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

DROP INDEX IF EXISTS <SCHEMA>.c_dokl_buf;
CREATE INDEX c_dokl_buf
    ON <SCHEMA>.dokl_buf USING btree
    (c_dokl ASC NULLS LAST)
    TABLESPACE pg_default;

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

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

END IF;


#[ KONEC SOUBORU ]#