ALTER TABLE AKUZ.T_POST DROP CONSTRAINT if exists FK_T_V002_PROFILE_T_POST_V002Profile;
ALTER TABLE AKUZ.T_PRESCRIPTION_OF_OUTCOME DROP CONSTRAINT if exists FK_T_V002_PROFILE_T_PRESCRIPTION_OF_OUTCOME_NAZ_PMP;
ALTER TABLE AKUZ.T_STAFF_DATA DROP CONSTRAINT if exists FK_T_V002_PROFILE_T_STAFF_DATA_ProfilV002;
ALTER TABLE AKUZ.T_STRUCTURE_BED DROP CONSTRAINT if exists FK_T_V002_PROFILE_T_STRUCTURE_BED_V002Profile;

ALTER TABLE AKUZ.T_V002_PROFILE DROP CONSTRAINT if exists PK_T_V002_PROFILE;
ALTER TABLE AKUZ.T_V002_PROFILE DROP CONSTRAINT if exists t_V002_profile_pkey;

ALTER TABLE AKUZ.T_V002_PROFILE ADD "v002profileid" uuid NULL;
UPDATE AKUZ.T_V002_PROFILE SET "v002profileid" = gen_random_uuid();
ALTER TABLE AKUZ.T_V002_PROFILE ALTER COLUMN "v002profileid" SET NOT NULL;
ALTER TABLE AKUZ.T_V002_PROFILE ADD CONSTRAINT PK_T_V002_PROFILE
PRIMARY KEY (V002ProfileID);


alter table AKUZ.T_POST rename column V002Profile to V002ProfileOld;

ALTER TABLE AKUZ.T_POST ADD "v002profile" uuid NULL;

ALTER TABLE AKUZ.T_POST ADD CONSTRAINT FK_T_V002_PROFILE_T_POST_V002Profile
FOREIGN KEY("v002profile") REFERENCES AKUZ.T_V002_PROFILE (V002ProfileID);

update AKUZ.T_POST as mrv
set V002Profile = vpm.V002ProfileID
from AKUZ.T_V002_PROFILE as vpm
where vpm.Id = mrv.V002ProfileOld;

alter table AKUZ.T_POST drop column V002ProfileOld;


alter table AKUZ.T_PRESCRIPTION_OF_OUTCOME rename column NAZ_PMP to NAZ_PMPOld;

ALTER TABLE AKUZ.T_PRESCRIPTION_OF_OUTCOME ADD NAZ_PMP uuid NULL;

ALTER TABLE AKUZ.T_PRESCRIPTION_OF_OUTCOME ADD CONSTRAINT FK_T_V002_PROFILE_T_PRESCRIPTION_OF_OUTCOME_NAZ_PMP
FOREIGN KEY(NAZ_PMP) REFERENCES AKUZ.T_V002_PROFILE (V002ProfileID);

update AKUZ.T_PRESCRIPTION_OF_OUTCOME as mrv
set NAZ_PMP = vpm.V002ProfileID
from AKUZ.T_V002_PROFILE as vpm
where vpm.Id = mrv.NAZ_PMPOld;

alter table AKUZ.T_PRESCRIPTION_OF_OUTCOME drop column NAZ_PMPOld;


alter table AKUZ.T_STAFF_DATA rename column ProfilV002 to ProfilV002Old;

ALTER TABLE AKUZ.T_STAFF_DATA ADD ProfilV002 uuid NULL;

ALTER TABLE AKUZ.T_STAFF_DATA ADD CONSTRAINT FK_T_V002_PROFILE_T_STAFF_DATA_ProfilV002
FOREIGN KEY(ProfilV002) REFERENCES AKUZ.T_V002_PROFILE (V002ProfileID);

update AKUZ.T_STAFF_DATA as mrv
set ProfilV002 = vpm.V002ProfileID
from AKUZ.T_V002_PROFILE as vpm
where vpm.Id = mrv.ProfilV002Old;

alter table AKUZ.T_STAFF_DATA drop column ProfilV002Old;


alter table AKUZ.T_STRUCTURE_BED rename column V002Profile to V002ProfileOld;

ALTER TABLE AKUZ.T_STRUCTURE_BED ADD V002Profile uuid NULL;

ALTER TABLE AKUZ.T_STRUCTURE_BED ADD CONSTRAINT FK_T_V002_PROFILE_T_STRUCTURE_BED_V002Profile
FOREIGN KEY(V002Profile) REFERENCES AKUZ.T_V002_PROFILE (V002ProfileID);

update AKUZ.T_STRUCTURE_BED as mrv
set V002Profile = vpm.V002ProfileID
from AKUZ.T_V002_PROFILE vpm
where vpm.Id = mrv.V002ProfileOld;

alter table AKUZ.T_STRUCTURE_BED drop column V002ProfileOld;

ALTER TABLE AKUZ.T_V002_PROFILE ADD "is_ident" integer NULL;

ALTER TABLE AKUZ.T_V002_PROFILE ADD "parent_id" integer NULL;

ALTER TABLE AKUZ.T_V002_PROFILE ALTER COLUMN "name" SET DATA TYPE varchar(512);