diff --git a/datamodel/changelogs/0001/03_tww_db_dss.sql b/datamodel/changelogs/0001/03_tww_db_dss.sql index 688709bfa..0a92bc7a6 100644 --- a/datamodel/changelogs/0001/03_tww_db_dss.sql +++ b/datamodel/changelogs/0001/03_tww_db_dss.sql @@ -32,6 +32,7 @@ CREATE TABLE tww_od.re_building_group_disposal CONSTRAINT pkey_tww_od_re_building_group_disposal_id PRIMARY KEY (id) ); COMMENT ON COLUMN tww_od.re_building_group_disposal.id IS 'UUID generated with uuid_generate_v4 see https://www.postgresql.org/docs/16/uuid-ossp.html#UUID-OSSP-FUNCTIONS-SECT'; + ------- CREATE TABLE tww_od.re_maintenance_event_wastewater_structure ( @@ -5179,3 +5180,8 @@ ALTER TABLE tww_od.farm ADD CONSTRAINT rel_od_farm_fk_dataprovider FOREIGN KEY ( CREATE UNIQUE INDEX in_od_hydraulic_char_data_identifier ON tww_od.hydraulic_char_data USING btree (identifier ASC NULLS LAST, fk_dataowner ASC NULLS LAST); CREATE UNIQUE INDEX in_od_catchment_area_totals_identifier ON tww_od.catchment_area_totals USING btree (identifier ASC NULLS LAST, fk_dataowner ASC NULLS LAST); CREATE UNIQUE INDEX in_od_building_group_identifier ON tww_od.building_group USING btree (identifier ASC NULLS LAST, fk_dataowner ASC NULLS LAST); + +-- For m:n relation tables to avoid duplicate entries +CREATE UNIQUE INDEX in_re_maintenance_event_wastewater_structure_fks ON tww_od.re_maintenance_event_wastewater_structure USING btree (fk_maintenance_event ASC NULLS LAST, fk_wastewater_structure ASC NULLS LAST); + +CREATE UNIQUE INDEX in_re_building_group_disposal_fks ON tww_od.re_building_group_disposal USING btree (fk_building_group ASC NULLS LAST, fk_disposal ASC NULLS LAST);