Skip to content

Commit

Permalink
#884 create latest mat view for intersection layer as well
Browse files Browse the repository at this point in the history
  • Loading branch information
chmnata committed Feb 26, 2024
1 parent 25e3dff commit 33cbb07
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);

Check notice on line 13 in gis/centreline/sql/create_matview_centreline_intersection_point_latest.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT05: Line is too long (131 > 100).

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.'

Check notice on line 19 in gis/centreline/sql/create_matview_centreline_intersection_point_latest.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT05: Line is too long (214 > 100).
19 changes: 19 additions & 0 deletions gis/centreline/sql/create_matview_intersection_latest.sql
Original file line number Diff line number Diff line change
@@ -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.'

Check notice on line 19 in gis/centreline/sql/create_matview_intersection_latest.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT05: Line is too long (164 > 100).
Original file line number Diff line number Diff line change
@@ -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.';

Check notice on line 17 in gis/centreline/sql/create_trigger_centreline_intersection_point_latest.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT05: Line is too long (179 > 100).
17 changes: 17 additions & 0 deletions gis/centreline/sql/create_trigger_intersection_latest.sql
Original file line number Diff line number Diff line change
@@ -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.';

Check notice on line 17 in gis/centreline/sql/create_trigger_intersection_latest.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT05: Line is too long (145 > 100).

0 comments on commit 33cbb07

Please sign in to comment.