#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    id_edi integer NOT NULL DEFAULT 0,
    subor character(99) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    dat_vyst date,
    ico character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    dic character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    icdph character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    partner character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    ulica character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    mesto character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    psc character(6) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    iban character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    swift character(10) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    suma numeric(20,10) NOT NULL DEFAULT 0,
    c_dokl integer NOT NULL DEFAULT 0,
    idriadok SERIAL,
    c_data smallint NOT NULL DEFAULT 1,
    c_faktury character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    edi_kod character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    edi_stred character(50) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (idriadok)
#[ CREATE TABLE KONEC ]#

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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='edi_hlav' and column_name='edi_stred') THEN
		ALTER TABLE <SCHEMA>.edi_hlav  ADD COLUMN edi_stred CHARACTER(30) NOT NULL DEFAULT ''::BPCHAR;
	END IF;

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

	IF  EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='edi_hlav' and column_name='edi_stred') THEN
		ALTER TABLE <SCHEMA>.edi_hlav ALTER COLUMN edi_stred TYPE character(50) ;
	END IF;

	IF  EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='edi_hlav' and column_name='subor') THEN
		ALTER TABLE <SCHEMA>.edi_hlav ALTER COLUMN subor TYPE character(99) ;
	END IF;

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

END IF;

#[ KONEC SOUBORU ]#