aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2023-03-05 14:29:29 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2023-03-05 19:04:21 +0900
commit131c856bdd5c48bbd8358fc8c1840fce4fcf2178 (patch)
treec413bc3099fafef9b89c55f6fb4f435ab8239582
parentefe664d3614e540ff381e8ac234a01ad177b7109 (diff)
Rename column of transactions from type to type_code.
-rw-r--r--deploy/insert_transaction.sql3
-rw-r--r--deploy/insert_transaction@v1.0.0-dev3.sql25
-rw-r--r--revert/insert_transaction.sql3
-rw-r--r--revert/insert_transaction@v1.0.0-dev3.sql25
-rw-r--r--sqitch.plan1
-rw-r--r--verify/insert_transaction@v1.0.0-dev3.sql7
6 files changed, 60 insertions, 4 deletions
diff --git a/deploy/insert_transaction.sql b/deploy/insert_transaction.sql
index 42e825d..6c39e9e 100644
--- a/deploy/insert_transaction.sql
+++ b/deploy/insert_transaction.sql
@@ -4,7 +4,6 @@
BEGIN;
-DROP FUNCTION kakeibo.insert_transaction(kakeibo.transaction_type, DATE, TEXT);
CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
p_type INTEGER,
p_date DATE,
@@ -14,7 +13,7 @@ DECLARE
inserted_id INTEGER;
BEGIN
INSERT INTO kakeibo.transactions (
- type, date, note
+ type_code, date, note
) VALUES (
p_type, p_date, p_note
) RETURNING id INTO inserted_id;
diff --git a/deploy/insert_transaction@v1.0.0-dev3.sql b/deploy/insert_transaction@v1.0.0-dev3.sql
new file mode 100644
index 0000000..42e825d
--- /dev/null
+++ b/deploy/insert_transaction@v1.0.0-dev3.sql
@@ -0,0 +1,25 @@
+-- Deploy kakeibo:insert_transaction to pg
+-- requires: appschema
+-- requires: transactions
+
+BEGIN;
+
+DROP FUNCTION kakeibo.insert_transaction(kakeibo.transaction_type, DATE, TEXT);
+CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
+ p_type INTEGER,
+ 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
index d15552f..be936fc 100644
--- a/revert/insert_transaction.sql
+++ b/revert/insert_transaction.sql
@@ -4,9 +4,8 @@
BEGIN;
-DROP FUNCTION kakeibo.insert_transaction(INTEGER, DATE, TEXT);
CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
- p_type kakeibo.transaction_type,
+ p_type INTEGER,
p_date DATE,
p_note TEXT
) RETURNS INTEGER AS $$
diff --git a/revert/insert_transaction@v1.0.0-dev3.sql b/revert/insert_transaction@v1.0.0-dev3.sql
new file mode 100644
index 0000000..d15552f
--- /dev/null
+++ b/revert/insert_transaction@v1.0.0-dev3.sql
@@ -0,0 +1,25 @@
+-- Deploy kakeibo:insert_transaction to pg
+-- requires: appschema
+-- requires: transactions
+
+BEGIN;
+
+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;
diff --git a/sqitch.plan b/sqitch.plan
index b479af5..3673630 100644
--- a/sqitch.plan
+++ b/sqitch.plan
@@ -24,3 +24,4 @@ types [appschema] 2023-03-05T03:45:31Z Masaya Tojo <masaya@tojo.tokyo> # Add typ
transactions_type_code [transactions] 2023-03-05T03:53:38Z Masaya Tojo <masaya@tojo.tokyo> # Rename column of transactions from type to type_code.
transactions_type_code_fkey [transactions types] 2023-03-05T04:00:45Z Masaya Tojo <masaya@tojo.tokyo> # Add foreign key constraint to transactions table referencing types table.
@v1.0.0-dev3 2023-03-05T05:01:10Z Masaya Tojo <masaya@tojo.tokyo> # Tag v1.0.0-dev3.
+insert_transaction [insert_transaction@v1.0.0-dev3 appschema transactions] 2023-03-05T05:28:42Z Masaya Tojo <masaya@tojo.tokyo> # Rename column of transactions from type to type_code.
diff --git a/verify/insert_transaction@v1.0.0-dev3.sql b/verify/insert_transaction@v1.0.0-dev3.sql
new file mode 100644
index 0000000..1c348f1
--- /dev/null
+++ b/verify/insert_transaction@v1.0.0-dev3.sql
@@ -0,0 +1,7 @@
+-- Verify kakeibo:insert_transaction on pg
+
+BEGIN;
+
+SELECT has_function_privilege('kakeibo.insert_transaction(INTEGER, date, text)', 'execute');
+
+ROLLBACK;