#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    nazev_klic character(25) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    nazev character(8) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    prg_dotaz character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    prg_natiz character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    pl_druh integer DEFAULT 0,
    zaokr smallint DEFAULT (0)::smallint,
    j0 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    j1 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    j2 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    j3 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    j4 character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    kod_pl character(5) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    do_recepce smallint NOT NULL DEFAULT 0,
    do_limitu smallint NOT NULL DEFAULT 0,
    order_en smallint NOT NULL DEFAULT 0,
    text smallint NOT NULL DEFAULT 0,
    cisfplat numeric(2,0) NOT NULL DEFAULT 0,
    typ_komb character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    komp_pol character(18) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    komp_pl character(8) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    zal_pl character(8) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    typpl character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    idriadok SERIAL,
    prplmencen smallint NOT NULL DEFAULT 0,
    nemen_cenu smallint NOT NULL DEFAULT 0,
    ajpozlave smallint NOT NULL DEFAULT 1,
    ajpocenovejhladine smallint NOT NULL DEFAULT 1,
    platimojazlava smallint NOT NULL DEFAULT 0,
    platimojahladina smallint NOT NULL DEFAULT 0,
    nfpl smallint NOT NULL DEFAULT 1,
    allow_tip boolean NOT NULL DEFAULT false,
    overpay smallint NOT NULL DEFAULT 0,
    poradie smallint NOT NULL DEFAULT 999,
    pocetkopii smallint NOT NULL DEFAULT 0,
    sdph_pl numeric(5,2) NOT NULL DEFAULT 1,
    terminal boolean NOT NULL DEFAULT false,
    odvod smallint NOT NULL DEFAULT 0,
    odovzdat character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (idriadok)
#[ CREATE TABLE KONEC ]#

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


COMMENT ON COLUMN <SCHEMA>.druhy_pl.overpay
    IS '0 - nemozem prekrocit hodntu uctu
				1 - mozem prekrocit a vydavam v hotovosti
				2 - mozem prekrocit a evidujem preplatok';


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


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


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

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

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

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

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


IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='druhy_pl' and column_name='allow_tip') THEN
			ALTER TABLE <SCHEMA>.druhy_pl   ADD COLUMN allow_tip boolean NOT NULL DEFAULT false;
END IF;

IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='druhy_pl' and column_name='overpay') THEN
			ALTER TABLE <SCHEMA>.druhy_pl   ADD COLUMN overpay smallint NOT NULL DEFAULT 0;
			COMMENT ON COLUMN <SCHEMA>.druhy_pl.overpay
			    IS '0 - nemozem prekrocit hodntu uctu
				1 - mozem prekrocit a vydavam v hotovosti
				2 - mozem prekrocit a evidujem preplatok';
END IF;


IF not EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='druhy_pl' and column_name='poradie') THEN
	ALTER TABLE <SCHEMA>.druhy_pl   ADD COLUMN poradie SMALLINT NOT NULL DEFAULT 999;
END IF;

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


	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='druhy_pl' and column_name='sdph_pl') THEN
		ALTER TABLE <SCHEMA>.druhy_pl  ADD COLUMN sdph_pl numeric(5, 2) NOT NULL DEFAULT 1 ;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='druhy_pl' and column_name='terminal') THEN
		ALTER TABLE <SCHEMA>.druhy_pl  ADD COLUMN terminal boolean NOT NULL DEFAULT false;
	END IF;

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

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

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

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

END IF;

#[ KONEC SOUBORU ]#