CREATE TABLE AKUZ.T_IPRA2_RHB_RES
(
    "ipra2rhbresid" uuid NOT NULL,
    "name" varchar(1024) NULL,
    "shname" varchar(64) NOT NULL
);

ALTER TABLE AKUZ.T_IPRA2_RHB_RES ADD CONSTRAINT PK_T_IPRA2_RHB_RES
PRIMARY KEY (Ipra2RhbResID);

insert into AKUZ.T_IPRA2_RHB_RES (Ipra2RhbResID, "name", SHNAME)
select gen_random_uuid() as Ipra2RhbResID
    , case when irr.SHNAME = 'не выполнено' then irr."name" else null end as "name"
    , irr.SHNAME as SHNAME
from AKUZ.T_IPRA_RHB_RES irr;

ALTER TABLE AKUZ.T_IPRA2_EXECUTION_EVENT ADD "result" uuid NOT NULL;

ALTER TABLE AKUZ.T_IPRA2_EXECUTION_EVENT ADD CONSTRAINT FK_T_IPRA2_RHB_RES_T_IPRA2_EXECUTION_EVENT_Result
FOREIGN KEY("result") REFERENCES AKUZ.T_IPRA2_RHB_RES (Ipra2RhbResID);