alter table vclib.t_entities_web_alias_access drop constraint if exists fk_t_entities_web_alias_t_entities_web_alias_access_entitiesweb;
alter table vclib.t_entities_web_alias drop constraint if exists fk_t_entities_web_alias_t_entities_web_alias_inheritsalias;
alter table vclib.t_entities_web_alias drop constraint if exists pk_t_entities_web_alias;

ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS ADD "entitieswebaliasid" uuid NULL;
UPDATE VCLib.T_ENTITIES_WEB_ALIAS SET "entitieswebaliasid" = gen_random_uuid();
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS ALTER COLUMN "entitieswebaliasid" SET NOT NULL;
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS ADD CONSTRAINT PK_T_ENTITIES_WEB_ALIAS
PRIMARY KEY (EntitiesWebAliasID);



alter table vclib.t_entities_web_alias_access rename column entitieswebalias to entitieswebaliasold;
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS_ACCESS ADD "entitieswebalias" uuid NULL;
UPDATE VCLib.T_ENTITIES_WEB_ALIAS_ACCESS ewa
SET "entitieswebalias" = (select EntitiesWebAliasID from VCLib.T_ENTITIES_WEB_ALIAS where Alias = ewa.EntitiesWebAliasOld);
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS_ACCESS ALTER COLUMN "entitieswebalias" SET NOT NULL;
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS_ACCESS ADD CONSTRAINT FK_T_ENTITIES_WEB_ALIAS_T_ENTITIES_WEB_ALIAS_ACCESS_EntitiesWebAlias
FOREIGN KEY("entitieswebalias") REFERENCES VCLib.T_ENTITIES_WEB_ALIAS (EntitiesWebAliasID);
alter table vclib.t_entities_web_alias_access drop column entitieswebaliasold;

alter table vclib.t_entities_web_alias rename column InheritsAlias to InheritsAliasOld;
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS ADD "inheritsalias" uuid NULL;
update vclib.t_entities_web_alias ewa
set InheritsAlias = (select EntitiesWebAliasID from VCLib.T_ENTITIES_WEB_ALIAS where Alias = ewa.InheritsAliasOld);
ALTER TABLE VCLib.T_ENTITIES_WEB_ALIAS ADD CONSTRAINT FK_T_ENTITIES_WEB_ALIAS_T_ENTITIES_WEB_ALIAS_InheritsAlias
FOREIGN KEY("inheritsalias") REFERENCES VCLib.T_ENTITIES_WEB_ALIAS (EntitiesWebAliasID);
alter table vclib.t_entities_web_alias drop column InheritsAliasOld;
