Skip to content

Commit

Permalink
fix(execute psector): harmonize audit_psector fields and correct trg_…
Browse files Browse the repository at this point in the history
…edit_psector
  • Loading branch information
albertbofill committed Sep 5, 2024
1 parent bb587ef commit 2905d1c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 31 deletions.
23 changes: 21 additions & 2 deletions updates/36/36012/ud/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psec
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_connec_traceability", "column":"placement_type", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_gully_traceability", "column":"placement_type", "dataType":"varchar(50)"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_node_traceability", "column":"access_type", "dataType":"text"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_connec_traceability", "column":"access_type", "dataType":"text"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"audit_psector_gully_traceability", "column":"access_type", "dataType":"text"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_gully_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"raingage", "column":"muni_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"rpt_inp_raingage", "column":"muni_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"connec", "column":"n_hydrometer", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"drainzone", "column":"sector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD", "table":"dma", "column":"sector_id", "dataType":"integer"}}$$);

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

-- 13/08/24
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"rpt_cat_result", "column":"iscorporate", "dataType":"boolean"}}$$);
Expand Down Expand Up @@ -325,6 +334,16 @@ SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"arc", "colu
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"connec", "column":"macrominsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"gully", "column":"macrominsector_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"minsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"minsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"minsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_gully_traceability", "column":"minsector_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_gully_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"cat_feature_node", "column":"graph_delimiter", "dataType":"text[]"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"sector", "column":"graphconfig", "dataType":"json"}}$$);
Expand Down
7 changes: 5 additions & 2 deletions updates/36/36012/ws/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,20 @@ SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"element", "
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"brand_id", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"model_id", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"serial_number", "dataType":"varchar(100)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"brand_id", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"model_id", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"serial_number", "dataType":"varchar(100)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_node_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"brand_id", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"model_id", "dataType":"varchar(50)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"serial_number", "dataType":"varchar(100)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_arc_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"label_quadrant", "dataType":"varchar(12)"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"audit_psector_connec_traceability", "column":"macrominsector_id", "dataType":"integer"}}$$);

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"connec", "column":"cat_valve", "dataType":"varchar(30)"}}$$);

Expand Down
65 changes: 38 additions & 27 deletions utils/ftrg/gw_trg_edit_psector.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ BEGIN
v_psector_geom = (SELECT the_geom FROM plan_psector WHERE psector_id=NEW.psector_id);

-- copy values into traceability tables
INSERT INTO audit_psector_connec_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_connec_traceability_id_seq'), psector_id, pc.state, doable, pc.arc_id, l.link_id, l.the_geom, now(), current_user, 'Execute psector',
connec_id, code, elevation, depth, c.connecat_id, c.sector_id, customer_code, c.state, c.state_type, c.arc_id, connec_length, annotation, observ, comment, c.dma_id,
c.presszone_id, soilcat_id, function_type, category_type, c.fluid_type, location_type, c.workcat_id, c.workcat_id_end, buildercat_id, c.builtdate, c.enddate, ownercat_id,
muni_id, postcode, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, c.descript, link, verified, rotation, c.the_geom, undelete,
label_x, label_y, label_rotation, publish, inventory, c.expl_id, num_value, c.feature_type, c.tstamp, pjoint_type, pjoint_id, c.lastupdate, c.lastupdate_user, c.insert_user,
c.minsector_id, c.dqa_id, c.staticpressure, district_id,adate, adescript, accessibility,workcat_id_plan,asset_id, c.epa_type, om_state, conserv_state, priority, valve_location,
valve_type, shutoff_valve, access_type, placement_type, crmzone_id,c.expl_id2, plot_code
FROM plan_psector_x_connec pc JOIN connec c USING (connec_id)
JOIN link l USING (link_id)
WHERE psector_id=NEW.psector_id;

IF v_projectype = 'WS' THEN

INSERT INTO audit_psector_connec_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_connec_traceability_id_seq'), psector_id, pc.state, doable, pc.arc_id, l.link_id, l.the_geom, now(), current_user, 'Execute psector',
connec_id, code, elevation, depth, c.connecat_id, c.sector_id, customer_code, c.state, c.state_type, c.arc_id, connec_length, annotation, observ, comment, c.dma_id,
c.presszone_id, soilcat_id, function_type, category_type, c.fluid_type, location_type, c.workcat_id, c.workcat_id_end, buildercat_id, c.builtdate, c.enddate, ownercat_id,
c.muni_id, postcode, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, c.descript, link, verified, rotation, c.the_geom, undelete,
label_x, label_y, label_rotation, publish, inventory, c.expl_id, num_value, c.feature_type, c.tstamp, pjoint_type, pjoint_id, c.lastupdate, c.lastupdate_user, c.insert_user,
c.minsector_id, c.dqa_id, c.staticpressure, district_id,adate, adescript, accessibility,workcat_id_plan,asset_id, c.epa_type, om_state, conserv_state, priority, valve_location,
valve_type, shutoff_valve, access_type, placement_type, crmzone_id,c.expl_id2, plot_code
FROM plan_psector_x_connec pc JOIN connec c USING (connec_id)
JOIN link l USING (link_id)
WHERE psector_id=NEW.psector_id;

-- arc & node insert is different from ud because UD has legacy of _sys_length & _sys_elev and the impossibility to remove it from old production environments
INSERT INTO audit_psector_arc_traceability
Expand Down Expand Up @@ -150,6 +150,12 @@ BEGIN
n.insert_user,matcat_id,district_id,workcat_id_plan,asset_id,drainzone_id,parent_id,expl_id2, adate, adescript
FROM plan_psector_x_node pn JOIN node n USING (node_id)
WHERE psector_id=NEW.psector_id;

INSERT INTO audit_psector_connec_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_connec_traceability_id_seq'), psector_id, pc.state, doable, pc.arc_id, l.link_id, l.the_geom, now(), current_user, 'Execute psector', connec.*
FROM plan_psector_x_connec pc JOIN connec USING (connec_id)
JOIN link l USING (link_id)
WHERE psector_id=NEW.psector_id;

INSERT INTO audit_psector_gully_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_gully_traceability_id_seq'), psector_id, pg.state, doable, pg.arc_id, l.link_id, l.the_geom, now(), current_user, 'Execute psector', gully.*
Expand Down Expand Up @@ -304,27 +310,26 @@ BEGIN
v_psector_geom = (SELECT the_geom FROM plan_psector WHERE psector_id=NEW.psector_id);

--set v_action when status Executed or Canceled
IF NEW.status = 0 THEN
v_action='Execute psector';
IF NEW.status = 0 THEN
v_action='Execute psector';
ELSIF NEW.status = 3 THEN
v_action='Cancel psector';
END IF;

-- copy values into traceability tables
INSERT INTO audit_psector_connec_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_connec_traceability_id_seq'), psector_id, pc.state, doable, pc.arc_id, l.link_id, l.the_geom, now(), current_user, v_action,
connec_id, code, elevation, depth, c.connecat_id, c.sector_id, customer_code, c.state, c.state_type, c.arc_id, connec_length, annotation, observ, comment, c.dma_id,
c.presszone_id, soilcat_id, function_type, category_type, c.fluid_type, location_type, c.workcat_id, c.workcat_id_end, buildercat_id, c.builtdate, c.enddate, ownercat_id,
muni_id, postcode, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, c.descript, link, verified, rotation, c.the_geom, undelete,
label_x, label_y, label_rotation, publish, inventory, c.expl_id, num_value, c.feature_type, c.tstamp, pjoint_type, pjoint_id, c.lastupdate, c.lastupdate_user, c.insert_user,
c.minsector_id, c.dqa_id, c.staticpressure, district_id,adate, adescript, accessibility,workcat_id_plan,asset_id, c.epa_type, om_state, conserv_state, priority, valve_location,
valve_type, shutoff_valve, access_type, placement_type, crmzone_id,c.expl_id2, plot_code
FROM plan_psector_x_connec pc JOIN connec c USING (connec_id)
JOIN link l USING (link_id)
WHERE psector_id=NEW.psector_id;


IF v_projectype = 'WS' THEN

INSERT INTO audit_psector_connec_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_connec_traceability_id_seq'), psector_id, pc.state, doable, pc.arc_id, l.link_id, l.the_geom, now(), current_user, v_action,
connec_id, code, elevation, depth, c.connecat_id, c.sector_id, customer_code, c.state, c.state_type, c.arc_id, connec_length, annotation, observ, comment, c.dma_id,
c.presszone_id, soilcat_id, function_type, category_type, c.fluid_type, location_type, c.workcat_id, c.workcat_id_end, buildercat_id, c.builtdate, c.enddate, ownercat_id,
c.muni_id, postcode, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, c.descript, link, verified, rotation, c.the_geom, undelete,
label_x, label_y, label_rotation, publish, inventory, c.expl_id, num_value, c.feature_type, c.tstamp, pjoint_type, pjoint_id, c.lastupdate, c.lastupdate_user, c.insert_user,
c.minsector_id, c.dqa_id, c.staticpressure, district_id,adate, adescript, accessibility,workcat_id_plan,asset_id, c.epa_type, om_state, conserv_state, priority, valve_location,
valve_type, shutoff_valve, access_type, placement_type, crmzone_id,c.expl_id2, plot_code
FROM plan_psector_x_connec pc JOIN connec c USING (connec_id)
JOIN link l USING (link_id)
WHERE psector_id=NEW.psector_id;

-- arc & node insert is different from ud because UD has legacy of _sys_length & _sys_elev and the impossibility to remove it from old production environments
INSERT INTO audit_psector_arc_traceability
Expand Down Expand Up @@ -361,6 +366,12 @@ BEGIN
n.insert_user,matcat_id,district_id,workcat_id_plan,asset_id,drainzone_id,parent_id,expl_id2, adate, adescript
FROM plan_psector_x_node pn JOIN node n USING (node_id)
WHERE psector_id=NEW.psector_id;

INSERT INTO audit_psector_connec_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_connec_traceability_id_seq'), psector_id, pc.state, doable, pc.arc_id, l.link_id, l.the_geom, now(), current_user, v_action, connec.*
FROM plan_psector_x_connec pc JOIN connec USING (connec_id)
JOIN link l USING (link_id)
WHERE psector_id=NEW.psector_id;

INSERT INTO audit_psector_gully_traceability
SELECT nextval('SCHEMA_NAME.audit_psector_gully_traceability_id_seq'), psector_id, pg.state, doable, pg.arc_id, l.link_id, l.the_geom, now(), current_user, v_action, gully.*
Expand Down

0 comments on commit 2905d1c

Please sign in to comment.