#[ ZACATEK SOUBORU ]#

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

#[ 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,
    mesiac integer,
    rok integer,
    typ_pohybu smallint NOT NULL DEFAULT 0,
    CONSTRAINT archivdoklady_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY> )
#[ CREATE TABLE KONEC ]#

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

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='archivdoklady_c_data') THEN
DROP INDEX IF EXISTS <SCHEMA>.archivdoklady_c_data;
CREATE INDEX archivdoklady_c_data
    ON <SCHEMA>.archivdoklady USING btree
    (c_data ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;
IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='archivdoklady_c_stredisk') THEN
DROP INDEX IF EXISTS <SCHEMA>.archivdoklady_c_stredisk;
CREATE INDEX archivdoklady_c_stredisk
    ON <SCHEMA>.archivdoklady USING btree
    (c_stredisk ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='archivdoklady_mesiac') THEN
DROP INDEX IF EXISTS <SCHEMA>.archivdoklady_mesiac;
CREATE INDEX archivdoklady_mesiac
    ON <SCHEMA>.archivdoklady USING btree
    (mesiac ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='archivdoklady_rok') THEN
DROP INDEX IF EXISTS <SCHEMA>.archivdoklady_rok;
CREATE INDEX archivdoklady_rok
    ON <SCHEMA>.archivdoklady USING btree
    (rok ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

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

END IF;

#[ KONEC SOUBORU ]#