#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    heslo character(12) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    username character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    user_id character(3) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    jazyk character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT '0'::bpchar,
    hash character(12) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hashfood character(12) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    hashoman character(12) COLLATE pg_catalog."default" NOT NULL DEFAULT ' '::bpchar,
    mzda numeric(20,10) NOT NULL DEFAULT (0),
    idriadok SERIAL,
    is_admin smallint NOT NULL DEFAULT 0,
    user_ean character(13) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hashfoodie character(100) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hashfoodie2 character(100) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    hashfoodie3 character(100) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    CONSTRAINT user_id UNIQUE (user_id),
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

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

	ALTER TABLE <SCHEMA>.users ALTER COLUMN heslo    TYPE character(20) COLLATE pg_catalog."default";
	ALTER TABLE <SCHEMA>.users ALTER COLUMN hash     TYPE character(20) COLLATE pg_catalog."default";
	ALTER TABLE <SCHEMA>.users ALTER COLUMN hashfood TYPE character(20) COLLATE pg_catalog."default";
	ALTER TABLE <SCHEMA>.users ALTER COLUMN hashoman TYPE character(20) COLLATE pg_catalog."default";

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


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

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

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

END IF;

#[ KONEC SOUBORU ]#