diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2023-02-28 10:11:02 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-02 09:22:35 +0900 |
commit | 8102191eb96a7f5a7cd2baf2711c273f179a11e4 (patch) | |
tree | 555c06fdd196db1a81ac6bec0c5368157f4371cd | |
parent | 54e3c3f3e15a01b4ebf6ed43cc4b64cfba59ff36 (diff) |
Add function to insert transaction.
-rw-r--r-- | deploy/insert_transaction.sql | 24 | ||||
-rw-r--r-- | revert/insert_transaction.sql | 7 | ||||
-rw-r--r-- | sqitch.plan | 1 | ||||
-rw-r--r-- | verify/insert_transaction.sql | 7 |
4 files changed, 39 insertions, 0 deletions
diff --git a/deploy/insert_transaction.sql b/deploy/insert_transaction.sql new file mode 100644 index 0000000..851b38e --- /dev/null +++ b/deploy/insert_transaction.sql @@ -0,0 +1,24 @@ +-- Deploy kakeibo:insert_transaction to pg +-- requires: appschema +-- requires: transactions + +BEGIN; + +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; diff --git a/revert/insert_transaction.sql b/revert/insert_transaction.sql new file mode 100644 index 0000000..d579ca6 --- /dev/null +++ b/revert/insert_transaction.sql @@ -0,0 +1,7 @@ +-- Revert kakeibo:insert_transaction from pg + +BEGIN; + +DROP FUNCTION kakeibo.insert_transaction; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index 8a0eab8..c572266 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -5,3 +5,4 @@ appschema 2023-02-26T06:27:59Z Masaya Tojo <masaya@tojo.tokyo> # Add schema for all kakeibo objects. transaction_type [appschema] 2023-02-27T15:51:38Z Masaya Tojo <masaya@tojo.tokyo> # Add transaction type. transactions [appschema transaction_type] 2023-02-27T15:53:02Z Masaya Tojo <masaya@tojo.tokyo> # Add table for tracking transactions. +insert_transaction [appschema transactions] 2023-02-28T01:06:21Z Masaya Tojo <masaya@tojo.tokyo> # Add function to insert transaction. diff --git a/verify/insert_transaction.sql b/verify/insert_transaction.sql new file mode 100644 index 0000000..a591157 --- /dev/null +++ b/verify/insert_transaction.sql @@ -0,0 +1,7 @@ +-- Verify kakeibo:insert_transaction on pg + +BEGIN; + +SELECT has_function_privilege('kakeibo.insert_transaction(kakeibo.transaction_type, date, text)', 'execute'); + +ROLLBACK; |