aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2023-02-28 21:40:20 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2023-03-02 09:22:36 +0900
commit0854294b374660178c3d62a75bdd9a554359dcb4 (patch)
tree278bc3b01af815004545d8cb33c0afc09a1a2ab4
parent343155aab78c28d6d09bea75671b390aec9599f6 (diff)
Add items table for tracking individual products in transaction.
-rw-r--r--deploy/items.sql18
-rw-r--r--revert/items.sql7
-rw-r--r--sqitch.plan1
-rw-r--r--verify/items.sql16
4 files changed, 42 insertions, 0 deletions
diff --git a/deploy/items.sql b/deploy/items.sql
new file mode 100644
index 0000000..0fd79e9
--- /dev/null
+++ b/deploy/items.sql
@@ -0,0 +1,18 @@
+-- Deploy kakeibo:items to pg
+-- requires: appschema
+-- requires: transactions
+
+BEGIN;
+
+CREATE TABLE kakeibo.items (
+ id SERIAL PRIMARY KEY,
+ transaction_id INTEGER NOT NULL REFERENCES kakeibo.transactions(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
+ category TEXT NOT NULL,
+ subcategory TEXT,
+ amount INTEGER NOT NULL CHECK (amount > 0),
+ note TEXT,
+ created_at TIMESTAMP NOT NULL DEFAULT NOW(),
+ updated_at TIMESTAMP NOT NULL DEFAULT NOW()
+);
+
+COMMIT;
diff --git a/revert/items.sql b/revert/items.sql
new file mode 100644
index 0000000..b36bf6b
--- /dev/null
+++ b/revert/items.sql
@@ -0,0 +1,7 @@
+-- Revert kakeibo:items from pg
+
+BEGIN;
+
+DROP TABLE kakeibo.items;
+
+COMMIT;
diff --git a/sqitch.plan b/sqitch.plan
index a385e5d..8bb9a76 100644
--- a/sqitch.plan
+++ b/sqitch.plan
@@ -7,3 +7,4 @@ transaction_type [appschema] 2023-02-27T15:51:38Z Masaya Tojo <masaya@tojo.tokyo
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.
delete_transaction [transactions appschema] 2023-02-28T12:00:07Z Masaya Tojo <masaya@tojo.tokyo> # Create a function to delete a transaction.
+items [appschema transactions] 2023-02-28T12:08:45Z Masaya Tojo <masaya@tojo.tokyo> # Add items table for tracking individual products in transaction.
diff --git a/verify/items.sql b/verify/items.sql
new file mode 100644
index 0000000..9a561cf
--- /dev/null
+++ b/verify/items.sql
@@ -0,0 +1,16 @@
+-- Verify kakeibo:items on pg
+
+BEGIN;
+
+SELECT id,
+ transaction_id,
+ category,
+ subcategory,
+ amount,
+ note,
+ created_at,
+ updated_at
+ FROM kakeibo.items
+ WHERE FALSE;
+
+ROLLBACK;