do $$ begin
ALTER TABLE AKUZ.T_VISION_DIAGNOSTICS DROP CONSTRAINT FK_T_MEDICAL_EXAMINATION_T_VISION_DIAGNOSTICS_MedicalE_BD022B4A;
ALTER TABLE AKUZ.T_VISION_DIAGNOSTICS RENAME "medicalexamination" to "ambulancecardrecord";
ALTER TABLE AKUZ.T_VISION_DIAGNOSTICS ADD CONSTRAINT FK_T_AMBULANCE_CARD_RECORD_T_VISION_DIAGNOSTICS_Ambula_ACC98808 FOREIGN KEY("ambulancecardrecord") REFERENCES AKUZ.T_AMBULANCE_CARD_RECORD (MedicalRecordID);

IF EXISTS(select * from pg_indexes where schemaname ilike 'AKUZ' and tablename ilike 'T_VISION_DIAGNOSTICS' and indexname ilike 'UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord')
THEN
drop index AKUZ.UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord;
END IF;
end; $$;
ALTER TABLE AKUZ.T_VISION_DIAGNOSTICS DROP CONSTRAINT if exists UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord;
ALTER TABLE AKUZ.T_VISION_DIAGNOSTICS DROP COLUMN if exists AmbulanceCardRecord_UQ;

CREATE UNIQUE INDEX UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord ON AKUZ.T_VISION_DIAGNOSTICS(AmbulanceCardRecord);
