From e36a6b94211badaaf868a2082c348a37e65d86e1 Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Tue, 28 Feb 2023 23:36:50 +0900
Subject: Add triger function to update a timestamp.

---
 deploy/update_timestamp.sql | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 deploy/update_timestamp.sql

(limited to 'deploy/update_timestamp.sql')

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;
-- 
cgit v1.2.3

