From a4a99033f2d3eb7e6d03387fe7e6618604885776 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sun, 12 Mar 2023 23:16:42 +0900 Subject: Add update_timestamp trigger to items table. --- deploy/items_update_timestamp.sql | 12 ++++++++++++ revert/items_update_timestamp.sql | 7 +++++++ sqitch.plan | 1 + verify/items_update_timestamp.sql | 14 ++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 deploy/items_update_timestamp.sql create mode 100644 revert/items_update_timestamp.sql create mode 100644 verify/items_update_timestamp.sql diff --git a/deploy/items_update_timestamp.sql b/deploy/items_update_timestamp.sql new file mode 100644 index 0000000..f9258b2 --- /dev/null +++ b/deploy/items_update_timestamp.sql @@ -0,0 +1,12 @@ +-- Deploy kakeibo:items_update_timestamp to pg +-- requires: items +-- requires: update_timestamp + +BEGIN; + +CREATE OR REPLACE TRIGGER update_timestamp + BEFORE UPDATE ON kakeibo.items + FOR EACH ROW + EXECUTE FUNCTION kakeibo.update_timestamp(); + +COMMIT; diff --git a/revert/items_update_timestamp.sql b/revert/items_update_timestamp.sql new file mode 100644 index 0000000..52ce12f --- /dev/null +++ b/revert/items_update_timestamp.sql @@ -0,0 +1,7 @@ +-- Revert kakeibo:items_update_timestamp from pg + +BEGIN; + +DROP TRIGGER update_timestamp ON kakeibo.items; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index 7f881f9..95b4dcb 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -11,3 +11,4 @@ delete_item [schema items] 2023-03-12T08:14:34Z Masaya Tojo delete_transaction [schema transactions] 2023-03-12T08:40:47Z Masaya Tojo # Add function to delete transaction. update_timestamp [schema] 2023-03-12T13:57:49Z Masaya Tojo # Add function to update timestamp. transactions_update_timestamp [transactions update_timestamp] 2023-03-12T14:10:42Z Masaya Tojo # Add update_timestamp trigger to transactions table. +items_update_timestamp [items update_timestamp] 2023-03-12T14:14:13Z Masaya Tojo # Add update_timestamp trigger to items table. diff --git a/verify/items_update_timestamp.sql b/verify/items_update_timestamp.sql new file mode 100644 index 0000000..c7fe432 --- /dev/null +++ b/verify/items_update_timestamp.sql @@ -0,0 +1,14 @@ +-- Verify kakeibo:items_update_timestamp on pg + +BEGIN; + +DO $$ + BEGIN + ASSERT (SELECT 1 from information_schema.triggers + WHERE trigger_schema = 'kakeibo' + AND event_object_table = 'transactions' + AND trigger_name = 'update_timestamp'); + END +$$; + +ROLLBACK; -- cgit v1.2.3