Skip to content

Commit

Permalink
feat(muni_id):Add fkey for tables om_visit, element, samplepoint, lin…
Browse files Browse the repository at this point in the history
…k, dimensions, minsector, pond & pool
  • Loading branch information
xtorret committed Aug 22, 2024
1 parent 408ff9f commit 819a585
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
48 changes: 44 additions & 4 deletions updates/36/36012/utils/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,47 @@ CREATE TABLE cat_style (
active bool DEFAULT true NULL,
CONSTRAINT cat_style_pkey PRIMARY KEY (id));


ALTER TABLE link ADD CONSTRAINT link_muni_id_fkey FOREIGN KEY (muni_id) REFERENCES ext_municipality (muni_id)
MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

do $$
declare
v_utils boolean;
begin
SELECT value::boolean INTO v_utils FROM config_param_system WHERE parameter='admin_utils_schema';

if v_utils is true then

-- create fk
ALTER TABLE SCHEMA_NAME.link ADD CONSTRAINT link_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.samplepoint ADD CONSTRAINT samplepoint_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.element ADD CONSTRAINT element_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.om_visit ADD CONSTRAINT om_visit_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.dimensions ADD CONSTRAINT dimensions_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

else

-- create fk
ALTER TABLE SCHEMA_NAME.link ADD CONSTRAINT link_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.samplepoint ADD CONSTRAINT samplepoint_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.element ADD CONSTRAINT element_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.om_visit ADD CONSTRAINT om_visit_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.dimensions ADD CONSTRAINT dimensions_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

end if;
end; $$;
34 changes: 34 additions & 0 deletions updates/36/36012/ws/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,37 @@ DROP VIEW IF EXISTS vi_parent_hydrometer;
DROP VIEW IF EXISTS v_edit_field_valve;

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"inp_shortpipe", "column":"custom_dint", "dataType":"integer"}}$$);


do $$
declare
v_utils boolean;
begin
SELECT value::boolean INTO v_utils FROM config_param_system WHERE parameter='admin_utils_schema';

if v_utils is true then

-- create fk
ALTER TABLE SCHEMA_NAME.minsector ADD CONSTRAINT minsectormuni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.pond ADD CONSTRAINT pond_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.pool ADD CONSTRAINT pool_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES utils.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

else

-- create fk
ALTER TABLE SCHEMA_NAME.minsector ADD CONSTRAINT minsectormuni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.pond ADD CONSTRAINT pond_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

ALTER TABLE SCHEMA_NAME.pool ADD CONSTRAINT pool_muni_id_fkey FOREIGN KEY (muni_id)
REFERENCES SCHEMA_NAME.ext_municipality (muni_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT;

end if;
end; $$;

0 comments on commit 819a585

Please sign in to comment.