From 62ce03796ba8e43277ba3f5acbf55cfb76591416 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Mon, 11 Mar 2024 00:31:23 +0900 Subject: Add update_updated_at trigger to articles table. --- deploy/articles_update_updated_at.sql | 15 +++++++++++++++ revert/articles_update_updated_at.sql | 9 +++++++++ sqitch.plan | 1 + verify/articles_update_updated_at.sql | 14 ++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 deploy/articles_update_updated_at.sql create mode 100644 revert/articles_update_updated_at.sql create mode 100644 verify/articles_update_updated_at.sql diff --git a/deploy/articles_update_updated_at.sql b/deploy/articles_update_updated_at.sql new file mode 100644 index 0000000..31b7ccd --- /dev/null +++ b/deploy/articles_update_updated_at.sql @@ -0,0 +1,15 @@ +-- Deploy diary:articles_update_updated_at to pg +-- requires: schema +-- requires: articles +-- requires: update_updated_at + +BEGIN; + +SET search_path to diary; + +CREATE OR REPLACE TRIGGER update_updated_at + BEFORE UPDATE ON articles + FOR EACH ROW + EXECUTE FUNCTION update_updated_at(); + +COMMIT; diff --git a/revert/articles_update_updated_at.sql b/revert/articles_update_updated_at.sql new file mode 100644 index 0000000..bed20cf --- /dev/null +++ b/revert/articles_update_updated_at.sql @@ -0,0 +1,9 @@ +-- Revert diary:articles_update_updated_at from pg + +BEGIN; + +SET search_path to diary; + +DROP TRIGGER update_updated_at ON articles; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index eea03de..47af4b2 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -5,3 +5,4 @@ schema 2024-03-10T11:00:19Z Masaya Tojo # Add schema for diary objects. update_updated_at [schema] 2024-03-10T11:29:05Z Masaya Tojo # Add function to update `updated_at` column. articles [schema] 2024-03-10T13:54:19Z Masaya Tojo # Add table manage diary articles. +articles_update_updated_at [schema articles update_updated_at] 2024-03-10T15:28:20Z Masaya Tojo # Add update_updated_at trigger to articles table. diff --git a/verify/articles_update_updated_at.sql b/verify/articles_update_updated_at.sql new file mode 100644 index 0000000..744b1fd --- /dev/null +++ b/verify/articles_update_updated_at.sql @@ -0,0 +1,14 @@ +-- Verify diary:articles_update_updated_at on pg + +BEGIN; + +DO $$ + BEGIN + ASSERT (SELECT 1 from information_schema.triggers + WHERE trigger_schema = 'diary' + AND event_object_table = 'articles' + AND trigger_name = 'update_updated_at'); + END +$$; + +ROLLBACK; -- cgit v1.2.3