From 3750a87a1b21ebb169d0bdb70833a85d7f20c6b1 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Wed, 1 Mar 2023 02:07:26 +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..31bb84c --- /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 5da13ea..c3c5b8c 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -12,3 +12,4 @@ insert_item [appschema items] 2023-02-28T13:13:22Z Masaya Tojo # Add function to delete item. update_timestamp [appschema] 2023-02-28T14:30:04Z Masaya Tojo # Add triger function to update a timestamp. transactions_update_timestamp [transactions update_timestamp] 2023-02-28T16:43:49Z Masaya Tojo # Add update_timestamp trigger to transactions table. +items_update_timestamp [items update_timestamp] 2023-02-28T17:04:02Z 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..a2daf86 --- /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 = 'items' + AND trigger_name = 'update_timestamp'); + END +$$; + +ROLLBACK; -- cgit v1.2.3