#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    idriadok integer NOT NULL DEFAULT 0,
    menobuf character(10) COLLATE pg_catalog."default" NOT NULL,
    c_data smallint NOT NULL DEFAULT 1,
    c_karty integer NOT NULL DEFAULT 0,
    nazev character(30) COLLATE pg_catalog."default",
    mnozstvi numeric(20,10) NOT NULL DEFAULT 0,
    dluh_mnoz numeric(20,10) NOT NULL DEFAULT 0,
    cena numeric(20,10) NOT NULL DEFAULT 0,
    cena_celk numeric(20,10) NOT NULL DEFAULT 0,
    cena_part numeric(20,10) NOT NULL DEFAULT 0,
    na_sklade numeric(20,10) NOT NULL DEFAULT 0,
    zustatek numeric(20,10) NOT NULL DEFAULT 0,
    druh character(10) COLLATE pg_catalog."default",
    c_stredisk integer NOT NULL DEFAULT 0,
    poradi integer NOT NULL DEFAULT 0,
    operace character(2) COLLATE pg_catalog."default",
    label character(1) COLLATE pg_catalog."default",
    dan numeric(5,3) DEFAULT 1,
    serial_no character(20) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    pov_objem numeric(20,10) NOT NULL DEFAULT 1,
    pc01 numeric(20,10),
    pc02 numeric(20,10),
    pc03 numeric(20,10),
    pc04 numeric(20,10),
    pc05 numeric(20,10),
    pc06 numeric(20,10),
    pc07 numeric(20,10),
    pc08 numeric(20,10),
    pc09 numeric(20,10),
    pc10 numeric(20,10),
    pc11 numeric(20,10),
    pc12 numeric(20,10),
    pc13 numeric(20,10),
    pc14 numeric(20,10),
    pc15 numeric(20,10),
    pc16 numeric(20,10),
    pc17 numeric(20,10),
    pc18 numeric(20,10),
    pc19 numeric(20,10),
    pc20 numeric(20,10),
    pc21 numeric(20,10),
    pc22 numeric(20,10),
    pc23 numeric(20,10),
    pc24 numeric(20,10),
    pc25 numeric(20,10),
    pc26 numeric(20,10),
    pc27 numeric(20,10),
    pc28 numeric(20,10),
    pc29 numeric(20,10),
    pc30 numeric(20,10),
    pc31 numeric(20,10),
    pc32 numeric(20,10),
    pc33 numeric(20,10),
    pc34 numeric(20,10),
    pc35 numeric(20,10),
    pc36 numeric(20,10),
    pc37 numeric(20,10),
    pc38 numeric(20,10),
    pc39 numeric(20,10),
    pc40 numeric(20,10),
    zmaz smallint DEFAULT 0,
    c_dokl integer NOT NULL DEFAULT 0,
    idr SERIAL,
    c_druhk integer NOT NULL DEFAULT 0,
    spdan numeric(20,10) NOT NULL DEFAULT 0,
    spstupne numeric(20,10) NOT NULL DEFAULT 0,
    c_druh integer DEFAULT 0,
    lieh numeric(12,4) NOT NULL DEFAULT 0,
    bufdidr integer NOT NULL DEFAULT 0,
    ean_koef numeric(20,10) NOT NULL DEFAULT 1,
    ean_mnoz numeric(20,10) NOT NULL DEFAULT 0,
    ean_cena numeric(20,10) NOT NULL DEFAULT 0,
    CONSTRAINT buffer_idr PRIMARY KEY (idr)
#[ CREATE TABLE KONEC ]#

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

DROP INDEX IF EXISTS <SCHEMA>.buffer_idr2;
CREATE INDEX buffer_idr2
    ON <SCHEMA>.buffer USING btree
    (idr ASC NULLS LAST)
    TABLESPACE pg_default;

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

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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='buffer' and column_name='ean_koef') THEN
		ALTER TABLE <SCHEMA>.buffer  ADD COLUMN ean_koef 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='buffer' and column_name='ean_mnoz') THEN
		ALTER TABLE <SCHEMA>.buffer  ADD COLUMN ean_mnoz numeric(20,10) NOT NULL DEFAULT 0;
	END IF;

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

	IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='buffer' and column_name='sscc') THEN
		ALTER TABLE <SCHEMA>.buffer ADD COLUMN sscc character varying;
	END IF;

END IF;

#[ KONEC SOUBORU ]#