DO $$
BEGIN
	IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='vclib' AND table_name='t_entities_attributes' AND column_name='attributeid')
	THEN

		CREATE SEQUENCE VCLib.T_ENTITIES_ATTRIBUTES_AttributeId_seq
		  INCREMENT 1
		  MINVALUE 1
		  MAXVALUE 9223372036854775807
		  START 1
		  CACHE 1;

		ALTER TABLE VCLib.T_ENTITIES_ATTRIBUTES ADD COLUMN AttributeId integer;
		ALTER TABLE VCLib.T_ENTITIES_ATTRIBUTES ALTER COLUMN AttributeId SET NOT NULL;
		ALTER TABLE VCLib.T_ENTITIES_ATTRIBUTES ALTER COLUMN AttributeId SET DEFAULT nextval('vclib.t_entities_attributes_attributeid_seq'::regclass);

	END IF;
END;
$$ Language plpgsql;
