do $$ begin
IF EXISTS(select * from pg_indexes where schemaname ilike 'AKUZ' and tablename ilike 'T_CDA_SECTION_WORK_CHILD' and indexname ilike 'UQ_T_CDA_SECTION_WORK_CHILD_CdaChildHealthState')
THEN
drop index AKUZ.UQ_T_CDA_SECTION_WORK_CHILD_CdaChildHealthState;
END IF;
end; $$;
ALTER TABLE AKUZ.T_CDA_SECTION_WORK_CHILD DROP CONSTRAINT if exists UQ_T_CDA_SECTION_WORK_CHILD_CdaChildHealthState;
ALTER TABLE AKUZ.T_CDA_SECTION_WORK_CHILD DROP COLUMN if exists CdaChildHealthState_UQ;

ALTER TABLE AKUZ.T_CDA_SECTION_WORK_CHILD ADD COLUMN CdaChildHealthState_UQ uuid;
UPDATE AKUZ.T_CDA_SECTION_WORK_CHILD SET CdaChildHealthState_UQ = CASE WHEN CdaChildHealthState IS NOT NULL THEN NULL ELSE CdaSectionWorkChildID END;

CREATE UNIQUE INDEX UQ_T_CDA_SECTION_WORK_CHILD_CdaChildHealthState ON AKUZ.T_CDA_SECTION_WORK_CHILD(CdaChildHealthState);
