From d91489e7ac55b55b5dcb3c270f85eaad88830f1d Mon Sep 17 00:00:00 2001 From: Alfred Nwolisa Date: Fri, 10 Jan 2025 14:39:11 -0500 Subject: [PATCH] Feat: Official Status Tag Update (#869) * Add trigger for tracking `official` field updates in `feed` This commit introduces a PostgreSQL trigger and associated function to log changes to the `official` field in the `public.feed` table. It also includes a query to set the `official` field for feeds meeting specific criteria. This enhances data auditability and ensures change history is recorded in `officialstatushistory`. * Removed trigger for logging official tag changes & replaced with direct query update to the 'officialstatushistory' table --- liquibase/changes/official_tag_update.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 liquibase/changes/official_tag_update.sql diff --git a/liquibase/changes/official_tag_update.sql b/liquibase/changes/official_tag_update.sql new file mode 100644 index 000000000..7baf86d19 --- /dev/null +++ b/liquibase/changes/official_tag_update.sql @@ -0,0 +1,20 @@ +-- Query to update official tag for feeds with contact email in the feed table where the source is mdb + +UPDATE public.feed f +SET official = TRUE +FROM public.externalid e +WHERE f.id = e.feed_id + AND f.feed_contact_email LIKE '%@%' + AND e.source = 'mdb'; + +-- Query to insert a record in officialstatushistory table for feeds with contact email in the feed table where the source is mdb +INSERT INTO public.officialstatushistory (is_official, feed_id, reviewer_email, timestamp, notes) +SELECT + official, + id, + 'api@mobilitydata.org', + NOW(), + 'Official status tag changed' +FROM public.feed +WHERE feed_contact_email LIKE '%@%' + AND official = TRUE;