From 85aa0f7fa89cad0cd81af87336d7f9d31bb19422 Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Sat, 4 Mar 2023 19:44:11 +0900
Subject: Change insert_transaction signature to use integer.

---
 revert/insert_transaction.sql | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

(limited to 'revert/insert_transaction.sql')

diff --git a/revert/insert_transaction.sql b/revert/insert_transaction.sql
index d579ca6..d15552f 100644
--- a/revert/insert_transaction.sql
+++ b/revert/insert_transaction.sql
@@ -1,7 +1,25 @@
--- Revert kakeibo:insert_transaction from pg
+-- Deploy kakeibo:insert_transaction to pg
+-- requires: appschema
+-- requires: transactions
 
 BEGIN;
 
-DROP FUNCTION kakeibo.insert_transaction;
+DROP FUNCTION kakeibo.insert_transaction(INTEGER, DATE, TEXT);
+CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
+  p_type kakeibo.transaction_type,
+  p_date DATE,
+  p_note TEXT
+) RETURNS INTEGER AS $$
+DECLARE
+  inserted_id INTEGER;
+BEGIN
+  INSERT INTO kakeibo.transactions (
+    type, date, note
+  ) VALUES (
+    p_type, p_date, p_note
+  ) RETURNING id INTO inserted_id;
+  RETURN inserted_id;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
 
 COMMIT;
-- 
cgit v1.2.3

