aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2023-03-06 02:04:29 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2023-03-06 02:04:29 +0900
commit79c9bd6a059050bfcaf879b1854550ccffaa4d15 (patch)
treefd8fe07ed547a40922f335ba1fbaab5471fd4e5a
parentb121761eb44b8fd8a8aee4e0945f6a7dcec9c719 (diff)
Add update_timestamp trigger to articles table.
-rw-r--r--deploy/articles_update_timestamp.sql12
-rw-r--r--revert/articles_update_timestamp.sql7
-rw-r--r--sqitch.plan1
-rw-r--r--verify/articles_update_timestamp.sql14
4 files changed, 34 insertions, 0 deletions
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 <masaya@tojo.tokyo> # Add table for link to diary articles.
transactions_article_id [transactions articles] 2023-03-05T14:25:46Z Masaya Tojo <masaya@tojo.tokyo> # Add article_id column to transactions table.
items_article_id [items articles] 2023-03-05T14:32:43Z Masaya Tojo <masaya@tojo.tokyo> # Add article_id column to items table.
+articles_update_timestamp [articles update_timestamp] 2023-03-05T17:01:58Z Masaya Tojo <masaya@tojo.tokyo> # 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;