-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
b80a161
commit 5b9148d
Showing
4 changed files
with
159 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
volumes/miovision/sql/inserts/insert-miovision_alerts_new.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
INSERT INTO miovision_api.alerts_new AS n ( | ||
alert_id, start_time, end_time, intersection_id, alert | ||
) | ||
VALUES %s | ||
ON CONFLICT (alert_id) | ||
DO UPDATE | ||
SET | ||
intersection_id = EXCLUDED.intersection_id, | ||
alert = EXCLUDED.alert, | ||
start_time = EXCLUDED.start_time, | ||
end_time = EXCLUDED.end_time | ||
WHERE n.alert_id = EXCLUDED.alert_id; | ||
|
||
--update foreign key referencing miovision_api.intersections | ||
--handles new records as well as old records with null intersection_uid (newly added intersections) | ||
UPDATE miovision_api.alerts_new AS n | ||
SET intersection_uid = i.intersection_uid | ||
FROM miovision_api.intersections AS i | ||
WHERE | ||
n.intersection_id = i.id | ||
AND n.intersection_uid IS NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- Table: miovision_api.alerts_new | ||
|
||
-- DROP TABLE IF EXISTS miovision_api.alerts_new; | ||
|
||
CREATE TABLE IF NOT EXISTS miovision_api.alerts_new | ||
( | ||
alert_id text COLLATE pg_catalog."default" NOT NULL, | ||
intersection_id text COLLATE pg_catalog."default" NOT NULL, | ||
alert text COLLATE pg_catalog."default" NOT NULL, | ||
start_time timestamp without time zone NOT NULL, | ||
end_time timestamp without time zone, | ||
intersection_uid integer, | ||
CONSTRAINT miovision_alerts_pkey_new PRIMARY KEY (alert_id), | ||
CONSTRAINT miov_alert_intersection_fkey_new FOREIGN KEY (intersection_uid) | ||
REFERENCES miovision_api.intersections (intersection_uid) MATCH FULL | ||
ON UPDATE NO ACTION | ||
ON DELETE NO ACTION | ||
) | ||
|
||
TABLESPACE pg_default; | ||
|
||
ALTER TABLE IF EXISTS miovision_api.alerts_new | ||
OWNER TO miovision_admins; | ||
|
||
REVOKE ALL ON TABLE miovision_api.alerts_new FROM bdit_humans; | ||
REVOKE ALL ON TABLE miovision_api.alerts_new FROM miovision_api_bot; | ||
|
||
GRANT SELECT ON TABLE miovision_api.alerts_new TO bdit_humans; | ||
|
||
GRANT ALL ON TABLE miovision_api.alerts_new TO miovision_admins; | ||
|
||
GRANT INSERT, SELECT, DELETE, UPDATE ON TABLE miovision_api.alerts_new TO miovision_api_bot; | ||
|
||
COMMENT ON TABLE miovision_api.alerts_new IS E'' | ||
'This table contains Miovision alerts pulled by a daily Airflow DAG `miovision_pull`, `pull_alerts` task. ' | ||
'Note: a more detailed description is available on Miovision One.'; | ||
|
||
COMMENT ON COLUMN miovision_api.alerts_new.intersection_id | ||
IS 'The intersection id, corresponding to intersections.intersection_id column'; | ||
|
||
COMMENT ON COLUMN miovision_api.alerts_new.alert IS E'' | ||
'Short text description of the alert. More detail on the different alerts can be found here: | ||
https://help.miovision.com/s/article/Alert-and-Notification-Types'; |