From eaee68ba5ffed646f51779e829163dc339d602a7 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Thu, 31 Aug 2023 00:40:54 +0900 Subject: Add update_timestamp trigger to transactions table --- deploy/transactions_update_timestamp.sql | 15 +++++++++++++++ revert/transactions_update_timestamp.sql | 9 +++++++++ sqitch.plan | 1 + verify/transactions_update_timestamp.sql | 14 ++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 deploy/transactions_update_timestamp.sql create mode 100644 revert/transactions_update_timestamp.sql create mode 100644 verify/transactions_update_timestamp.sql diff --git a/deploy/transactions_update_timestamp.sql b/deploy/transactions_update_timestamp.sql new file mode 100644 index 0000000..e893986 --- /dev/null +++ b/deploy/transactions_update_timestamp.sql @@ -0,0 +1,15 @@ +-- Deploy photos:transactions_update_timestamp to pg +-- requires: schema +-- requires: transactions +-- requires: update_timestamp + +BEGIN; + +SET search_path to photos; + +CREATE OR REPLACE TRIGGER update_timestamp + BEFORE UPDATE ON transactions + FOR EACH ROW + EXECUTE FUNCTION update_timestamp(); + +COMMIT; diff --git a/revert/transactions_update_timestamp.sql b/revert/transactions_update_timestamp.sql new file mode 100644 index 0000000..4c60c2f --- /dev/null +++ b/revert/transactions_update_timestamp.sql @@ -0,0 +1,9 @@ +-- Revert photos:transactions_update_timestamp from pg + +BEGIN; + +SET search_path to photos; + +DROP TRIGGER update_timestamp ON transactions; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index dadb8a8..aa15f30 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -9,3 +9,4 @@ photos_update_timestamp [schema photos update_timestamp] 2023-08-29T15:15:40Z Ma diaries [schema photos] 2023-08-29T15:30:42Z Masaya Tojo # Add table to manage diaries diaries_update_timestamp [schema diaries update_timestamp] 2023-08-29T15:57:21Z Masaya Tojo # Add update_timestamp trigger to diaries table transactions [schema photos] 2023-08-30T15:06:32Z Masaya Tojo # Add table to manage transactions +transactions_update_timestamp [schema transactions update_timestamp] 2023-08-30T15:38:02Z Masaya Tojo # Add update_timestamp trigger to transactions table diff --git a/verify/transactions_update_timestamp.sql b/verify/transactions_update_timestamp.sql new file mode 100644 index 0000000..079dcd7 --- /dev/null +++ b/verify/transactions_update_timestamp.sql @@ -0,0 +1,14 @@ +-- Verify photos:transactions_update_timestamp on pg + +BEGIN; + +DO $$ + BEGIN + ASSERT (SELECT 1 from information_schema.triggers + WHERE trigger_schema = 'photos' + AND event_object_table = 'transactions' + AND trigger_name = 'update_timestamp'); + END +$$; + +ROLLBACK; -- cgit v1.2.3