aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2023-03-13 00:16:52 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2023-03-13 00:17:08 +0900
commit170788cd42cc54c81f2b3e49ee12626145afe687 (patch)
treecc0b3b41677b6cb37aef36cf076a441cfc3c1c2f
parent05b6e730fa81a4ec02fbf361967896f0c9f3a2d4 (diff)
Add article_id column to items table.
-rw-r--r--deploy/items.sql15
-rw-r--r--deploy/items@v1.0.0-alpha.1.sql18
-rw-r--r--revert/items.sql7
-rw-r--r--revert/items@v1.0.0-alpha.1.sql7
-rw-r--r--sqitch.plan1
-rw-r--r--verify/items.sql3
-rw-r--r--verify/items@v1.0.0-alpha.1.sql16
7 files changed, 54 insertions, 13 deletions
diff --git a/deploy/items.sql b/deploy/items.sql
index 0a43f8b..d95fbf5 100644
--- a/deploy/items.sql
+++ b/deploy/items.sql
@@ -1,18 +1,13 @@
-- Deploy kakeibo:items to pg
-- requires: schema
-- requires: transactions
+-- requires: articles
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 CHECK (note <> ''),
- amount INTEGER NOT NULL CHECK (amount > 0),
- note TEXT CHECK (note <> '') ,
- created_at TIMESTAMP NOT NULL DEFAULT NOW(),
- updated_at TIMESTAMP NOT NULL DEFAULT NOW()
-);
+ALTER TABLE kakeibo.items
+ ADD COLUMN article_id INTEGER,
+ ADD CONSTRAINT transactions_article_id_fkey
+ FOREIGN KEY (article_id) REFERENCES kakeibo.articles (id);
COMMIT;
diff --git a/deploy/items@v1.0.0-alpha.1.sql b/deploy/items@v1.0.0-alpha.1.sql
new file mode 100644
index 0000000..0a43f8b
--- /dev/null
+++ b/deploy/items@v1.0.0-alpha.1.sql
@@ -0,0 +1,18 @@
+-- Deploy kakeibo:items to pg
+-- requires: schema
+-- 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 CHECK (note <> ''),
+ amount INTEGER NOT NULL CHECK (amount > 0),
+ note TEXT CHECK (note <> '') ,
+ 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
index b36bf6b..c8cbcd5 100644
--- a/revert/items.sql
+++ b/revert/items.sql
@@ -1,7 +1,10 @@
--- Revert kakeibo:items from pg
+-- Deploy kakeibo:items to pg
+-- requires: schema
+-- requires: transactions
BEGIN;
-DROP TABLE kakeibo.items;
+ALTER TABLE kakeibo.items
+ DROP COLUMN article_id;
COMMIT;
diff --git a/revert/items@v1.0.0-alpha.1.sql b/revert/items@v1.0.0-alpha.1.sql
new file mode 100644
index 0000000..b36bf6b
--- /dev/null
+++ b/revert/items@v1.0.0-alpha.1.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 a3f99dc..0fa416b 100644
--- a/sqitch.plan
+++ b/sqitch.plan
@@ -16,3 +16,4 @@ items_update_timestamp [items update_timestamp] 2023-03-12T14:14:13Z Masaya Tojo
articles [schema] 2023-03-12T14:43:06Z Masaya Tojo <masaya@tojo.tokyo> # Add table to manage articles.
transactions [transactions@v1.0.0-alpha.1 articles] 2023-03-12T15:06:03Z Masaya Tojo <masaya@tojo.tokyo> # Add article_id column to transactions table.
+items [items@v1.0.0-alpha.1 articles] 2023-03-12T15:12:15Z Masaya Tojo <masaya@tojo.tokyo> # Add article_id column to items table.
diff --git a/verify/items.sql b/verify/items.sql
index 9a561cf..22a4ee3 100644
--- a/verify/items.sql
+++ b/verify/items.sql
@@ -9,7 +9,8 @@ SELECT id,
amount,
note,
created_at,
- updated_at
+ updated_at,
+ article_id
FROM kakeibo.items
WHERE FALSE;
diff --git a/verify/items@v1.0.0-alpha.1.sql b/verify/items@v1.0.0-alpha.1.sql
new file mode 100644
index 0000000..9a561cf
--- /dev/null
+++ b/verify/items@v1.0.0-alpha.1.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;