diff --git a/gis/centreline/sql/create_matview_centreline_intersection_point_latest.sql b/gis/centreline/sql/create_matview_centreline_intersection_point_latest.sql new file mode 100644 index 000000000..725c1c18c --- /dev/null +++ b/gis/centreline/sql/create_matview_centreline_intersection_point_latest.sql @@ -0,0 +1,19 @@ +CREATE MATERIALIZED VIEW gis_core.centreline_intersection_point_latest AS + +SELECT * +FROM gis_core.centreline_intersection_point +WHERE version_date = (SELECT MAX(version_date) FROM gis_core.centreline_intersection_point); + +CREATE TRIGGER refresh_trigger +AFTER INSERT OR UPDATE OR DELETE +ON gis_core.centreline_intersection_point +FOR EACH STATEMENT +EXECUTE PROCEDURE gis_core.centreline_intersection_point_latest_trigger(); + +CREATE INDEX gis_core_centreline_intersection_point_latest_geom ON gis_core.centreline_intersection_point_latest USING gist (geom); + +ALTER MATERIALIZED VIEW gis_core.centreline_intersection_point_latest OWNER TO gis_admins; + +GRANT SELECT ON gis_core.centreline_intersection_point_latest TO bdit_humans; + +COMMENT ON MATERIALIZED VIEW gis_core.centreline_intersection_point_latest IS 'Materialized view containing the latest version of centreline intersection point, derived from gis_core.centreline_intersection_point.' diff --git a/gis/centreline/sql/create_matview_intersection_latest.sql b/gis/centreline/sql/create_matview_intersection_latest.sql new file mode 100644 index 000000000..a7b0fc55a --- /dev/null +++ b/gis/centreline/sql/create_matview_intersection_latest.sql @@ -0,0 +1,19 @@ +CREATE MATERIALIZED VIEW gis_core.intersection_latest AS + +SELECT * +FROM gis_core.intersection +WHERE version_date = (SELECT MAX(version_date) FROM gis_core.intersection); + +CREATE TRIGGER refresh_trigger +AFTER INSERT OR UPDATE OR DELETE +ON gis_core.intersection +FOR EACH STATEMENT +EXECUTE PROCEDURE gis_core.intersection_latest_trigger(); + +CREATE INDEX gis_core_intersection_latest_geom ON gis_core.intersection_latest USING gist (geom); + +ALTER MATERIALIZED VIEW gis_core.intersection_latest OWNER TO gis_admins; + +GRANT SELECT ON gis_core.intersection_latest TO bdit_humans; + +COMMENT ON MATERIALIZED VIEW gis_core.intersection_latest IS 'Materialized view containing the latest version of intersection , derived from gis_core.intersection.' \ No newline at end of file diff --git a/gis/centreline/sql/create_trigger_centreline_intersection_point_latest.sql b/gis/centreline/sql/create_trigger_centreline_intersection_point_latest.sql new file mode 100644 index 000000000..89d000279 --- /dev/null +++ b/gis/centreline/sql/create_trigger_centreline_intersection_point_latest.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE FUNCTION gis_core.centreline_intersection_point_latest_trigger() +RETURNS trigger +LANGUAGE 'plpgsql' +COST 100 +VOLATILE NOT LEAKPROOF SECURITY DEFINER +AS $BODY$ +BEGIN + +REFRESH MATERIALIZED VIEW gis_core.centreline_intersection_point_latest; +RETURN NULL; + +END; +$BODY$; + +ALTER FUNCTION gis_core.centreline_intersection_point_latest_trigger() OWNER TO gis_admins; + +COMMENT ON FUNCTION gis_core.centreline_intersection_point_latest_trigger() IS 'Trigger fuction that refreshes the centreline_intersection_point_latest mat view after an update.'; \ No newline at end of file diff --git a/gis/centreline/sql/create_trigger_intersection_latest.sql b/gis/centreline/sql/create_trigger_intersection_latest.sql new file mode 100644 index 000000000..17ef9b1d3 --- /dev/null +++ b/gis/centreline/sql/create_trigger_intersection_latest.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE FUNCTION gis_core.intersection_latest_trigger() +RETURNS trigger +LANGUAGE 'plpgsql' +COST 100 +VOLATILE NOT LEAKPROOF SECURITY DEFINER +AS $BODY$ +BEGIN + +REFRESH MATERIALIZED VIEW gis_core.intersection_latest; +RETURN NULL; + +END; +$BODY$; + +ALTER FUNCTION gis_core.intersection_latest_trigger() OWNER TO gis_admins; + +COMMENT ON FUNCTION gis_core.intersection_latest_trigger() IS 'Trigger fuction that refreshes the intersection_latest mat view after an update.'; \ No newline at end of file