From 79c9bd6a059050bfcaf879b1854550ccffaa4d15 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Mon, 6 Mar 2023 02:04:29 +0900 Subject: Add update_timestamp trigger to articles table. --- deploy/articles_update_timestamp.sql | 12 ++++++++++++ revert/articles_update_timestamp.sql | 7 +++++++ sqitch.plan | 1 + verify/articles_update_timestamp.sql | 14 ++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 deploy/articles_update_timestamp.sql create mode 100644 revert/articles_update_timestamp.sql create mode 100644 verify/articles_update_timestamp.sql diff --git a/deploy/articles_update_timestamp.sql b/deploy/articles_update_timestamp.sql new file mode 100644 index 0000000..143bad4 --- /dev/null +++ b/deploy/articles_update_timestamp.sql @@ -0,0 +1,12 @@ +-- Deploy kakeibo:articles_update_timestamp to pg +-- requires: articles +-- requires: update_timestamp + +BEGIN; + +CREATE OR REPLACE TRIGGER update_timestamp + BEFORE UPDATE ON kakeibo.articles + FOR EACH ROW + EXECUTE FUNCTION kakeibo.update_timestamp(); + +COMMIT; diff --git a/revert/articles_update_timestamp.sql b/revert/articles_update_timestamp.sql new file mode 100644 index 0000000..3ce73d1 --- /dev/null +++ b/revert/articles_update_timestamp.sql @@ -0,0 +1,7 @@ +-- Revert kakeibo:articles_update_timestamp from pg + +BEGIN; + +DROP TRIGGER update_timestamp ON kakeibo.articles; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index 0cea7ae..240155c 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -30,3 +30,4 @@ insert_transaction [insert_transaction@v1.0.0-dev3 appschema transactions] 2023- articles [appschema] 2023-03-05T14:01:38Z Masaya Tojo # Add table for link to diary articles. transactions_article_id [transactions articles] 2023-03-05T14:25:46Z Masaya Tojo # Add article_id column to transactions table. items_article_id [items articles] 2023-03-05T14:32:43Z Masaya Tojo # Add article_id column to items table. +articles_update_timestamp [articles update_timestamp] 2023-03-05T17:01:58Z Masaya Tojo # Add update_timestamp trigger to articles table. diff --git a/verify/articles_update_timestamp.sql b/verify/articles_update_timestamp.sql new file mode 100644 index 0000000..f1952b3 --- /dev/null +++ b/verify/articles_update_timestamp.sql @@ -0,0 +1,14 @@ +-- Verify kakeibo:articles_update_timestamp on pg + +BEGIN; + +DO $$ + BEGIN + ASSERT (SELECT 1 from information_schema.triggers + WHERE trigger_schema = 'kakeibo' + AND event_object_table = 'articles' + AND trigger_name = 'update_timestamp'); + END +$$; + +ROLLBACK; -- cgit v1.2.3