ALTER TABLE AKUZ.T_ADDRESS ADD "cdasectiondocinfochemicalpoisoning" uuid NULL;
ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_CDA_SECTION_DOCINFO_CHEMICAL_POISONING_T_ADDRESS__813E7310
FOREIGN KEY("cdasectiondocinfochemicalpoisoning") REFERENCES AKUZ.T_CDA_SECTION_DOCINFO_CHEMICAL_POISONING (CdaSectionID);

ALTER TABLE AKUZ.T_ADDRESS ADD "cdasectiondocinfoabsencecontactsinfectious" uuid NULL;
ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_CDA_SECTION_DOCINFO_ABSENCE_CONTACTS_INFECTIOUS_T_F9C9B44E
FOREIGN KEY("cdasectiondocinfoabsencecontactsinfectious") REFERENCES AKUZ.T_CDA_SECTION_DOCINFO_ABSENCE_CONTACTS_INFECTIOUS (CdaSectionID);

ALTER TABLE AKUZ.T_ADDRESS ADD "cdasectionworkmedcertificate" uuid NULL;
ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_CDA_SECTION_WORK_MED_CERTIFICATE_T_ADDRESS_CdaSec_4B117CAB
FOREIGN KEY("cdasectionworkmedcertificate") REFERENCES AKUZ.T_CDA_SECTION_WORK_MED_CERTIFICATE (CdaSectionID);

ALTER TABLE AKUZ.T_ADDRESS ADD "cdaworkplace" uuid NULL;
ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_CDA_WORKPLACE_T_ADDRESS_CdaWorkplace
FOREIGN KEY("cdaworkplace") REFERENCES AKUZ.T_CDA_WORKPLACE (CdaWorkplaceID);

ALTER TABLE AKUZ.T_ADDRESS ADD "hosplanamsocanamedu" uuid NULL;
ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_HOSP_LANAM_SOCANAM_EDU_T_ADDRESS_HospLanamSocanamEdu
FOREIGN KEY("hosplanamsocanamedu") REFERENCES AKUZ.T_HOSP_LANAM_SOCANAM_EDU (HospLanamSocanamEduID);

-- Tables

-- Alters

ALTER TABLE AKUZ.T_ADDRESS ADD "deadpatinfoperinataldeathplace" uuid NULL;

ALTER TABLE AKUZ.T_ADDRESS ADD "deadpatinfoperinatalbirthplace" uuid NULL;

ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_CDA_SECTION_DEADPATINFO_PERINATAL_T_ADDRESS_Deadp_8A91F2C0
FOREIGN KEY("deadpatinfoperinataldeathplace") REFERENCES AKUZ.T_CDA_SECTION_DEADPATINFO_PERINATAL (CdaSectionID);

ALTER TABLE AKUZ.T_ADDRESS ADD CONSTRAINT FK_T_CDA_SECTION_DEADPATINFO_PERINATAL_T_ADDRESS_Deadp_938F475B
FOREIGN KEY("deadpatinfoperinatalbirthplace") REFERENCES AKUZ.T_CDA_SECTION_DEADPATINFO_PERINATAL (CdaSectionID);



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

CREATE UNIQUE INDEX UQ_T_ADDRESS_HospLanamSocanamEdu ON AKUZ.T_ADDRESS(HospLanamSocanamEdu);

--T_CDA_WORKPLACE
ALTER TABLE AKUZ.T_CDA_WORKPLACE ALTER COLUMN "address" DROP NOT NULL;
ALTER TABLE AKUZ.T_CDA_WORKPLACE ALTER COLUMN "ehrrusj5phs5f9ra" DROP NOT NULL;

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

CREATE UNIQUE INDEX UQ_T_ADDRESS_CdaWorkplace ON AKUZ.T_ADDRESS(CdaWorkplace);

--T_CDA_SECTION_WORK_MED_CERTIFICATE

ALTER TABLE AKUZ.T_CDA_SECTION_WORK_MED_CERTIFICATE ALTER COLUMN "ehrrusj5phs5f9ra" DROP NOT NULL;
ALTER TABLE AKUZ.T_CDA_SECTION_WORK_MED_CERTIFICATE ALTER COLUMN "textaddress" DROP NOT NULL;

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

CREATE UNIQUE INDEX UQ_T_ADDRESS_CdaSectionWorkMedCertificate ON AKUZ.T_ADDRESS(CdaSectionWorkMedCertificate);

--T_CDA_SECTION_DOCINFO_CHEMICAL_POISONING

ALTER TABLE AKUZ.T_CDA_SECTION_DOCINFO_CHEMICAL_POISONING ALTER COLUMN "fulladdr" DROP NOT NULL;
ALTER TABLE AKUZ.T_CDA_SECTION_DOCINFO_CHEMICAL_POISONING ALTER COLUMN "flatnumber" DROP NOT NULL;

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

CREATE UNIQUE INDEX UQ_T_ADDRESS_CdaSectionDocinfoChemicalPoisoning ON AKUZ.T_ADDRESS(CdaSectionDocinfoChemicalPoisoning);

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

CREATE UNIQUE INDEX UQ_T_ADDRESS_CdaSectionDocinfoAbsenceContactsInfectious ON AKUZ.T_ADDRESS(CdaSectionDocinfoAbsenceContactsInfectious);


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

CREATE UNIQUE INDEX UQ_T_ADDRESS_DeadpatinfoPerinatalDeathPlace ON AKUZ.T_ADDRESS(DeadpatinfoPerinatalDeathPlace);

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

CREATE UNIQUE INDEX UQ_T_ADDRESS_DeadpatinfoPerinatalBirthPlace ON AKUZ.T_ADDRESS(DeadpatinfoPerinatalBirthPlace);

