aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2023-02-28 23:36:50 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2023-03-02 09:22:36 +0900
commite36a6b94211badaaf868a2082c348a37e65d86e1 (patch)
treefdaadc656110a680e6d2da7e86d105330f593e03
parent438a85fd3a2ea8dd4fa48df5537c1db2c0e90878 (diff)
Add triger function to update a timestamp.
-rw-r--r--deploy/update_timestamp.sql14
-rw-r--r--revert/update_timestamp.sql7
-rw-r--r--sqitch.plan1
-rw-r--r--verify/update_timestamp.sql7
4 files changed, 29 insertions, 0 deletions
diff --git a/deploy/update_timestamp.sql b/deploy/update_timestamp.sql
new file mode 100644
index 0000000..246c57f
--- /dev/null
+++ b/deploy/update_timestamp.sql
@@ -0,0 +1,14 @@
+-- Deploy kakeibo:update_timestamp to pg
+-- requires: appschema
+
+BEGIN;
+
+CREATE OR REPLACE FUNCTION kakeibo.update_timestamp()
+ RETURNS TRIGGER AS $$
+BEGIN
+ NEW.updated_at = NOW();
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql;
+
+COMMIT;
diff --git a/revert/update_timestamp.sql b/revert/update_timestamp.sql
new file mode 100644
index 0000000..07074ac
--- /dev/null
+++ b/revert/update_timestamp.sql
@@ -0,0 +1,7 @@
+-- Revert kakeibo:update_timestamp from pg
+
+BEGIN;
+
+DROP FUNCTION kakeibo.update_timestamp;
+
+COMMIT;
diff --git a/sqitch.plan b/sqitch.plan
index 9247959..de81c12 100644
--- a/sqitch.plan
+++ b/sqitch.plan
@@ -10,3 +10,4 @@ delete_transaction [transactions appschema] 2023-02-28T12:00:07Z Masaya Tojo <ma
items [appschema transactions] 2023-02-28T12:08:45Z Masaya Tojo <masaya@tojo.tokyo> # Add items table for tracking individual products in transaction.
insert_item [appschema items] 2023-02-28T13:13:22Z Masaya Tojo <masaya@tojo.tokyo> # Add function to insert item.
delete_item [appschema items] 2023-02-28T13:13:39Z Masaya Tojo <masaya@tojo.tokyo> # Add function to delete item.
+update_timestamp [appschema] 2023-02-28T14:30:04Z Masaya Tojo <masaya@tojo.tokyo> # Add triger function to update a timestamp.
diff --git a/verify/update_timestamp.sql b/verify/update_timestamp.sql
new file mode 100644
index 0000000..80fb7db
--- /dev/null
+++ b/verify/update_timestamp.sql
@@ -0,0 +1,7 @@
+-- Verify kakeibo:update_timestamp on pg
+
+BEGIN;
+
+SELECT has_function_privilege('kakeibo.update_timestamp()', 'execute');
+
+ROLLBACK;