aboutsummaryrefslogtreecommitdiff
path: root/deploy
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 /deploy
parent05b6e730fa81a4ec02fbf361967896f0c9f3a2d4 (diff)
Add article_id column to items table.
Diffstat (limited to 'deploy')
-rw-r--r--deploy/items.sql15
-rw-r--r--deploy/items@v1.0.0-alpha.1.sql18
2 files changed, 23 insertions, 10 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;