From 170788cd42cc54c81f2b3e49ee12626145afe687 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Mon, 13 Mar 2023 00:16:52 +0900 Subject: Add article_id column to items table. --- deploy/items.sql | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'deploy/items.sql') 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; -- cgit v1.2.3