From 5d7203d5ca85c44391d4bb250f8fbb6ecd7afd29 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sat, 8 Apr 2023 15:14:12 +0900 Subject: Rename type_code column to type and change type to transaction_type. --- deploy/kakeibo.transactions.sql | 9 ++++++--- deploy/kakeibo.transactions@v1.0.0-alpha.4.sql | 12 ++++++++++++ revert/kakeibo.transactions.sql | 8 ++++++-- revert/kakeibo.transactions@v1.0.0-alpha.4.sql | 8 ++++++++ sqitch.plan | 1 + verify/kakeibo.transactions.sql | 2 +- verify/kakeibo.transactions@v1.0.0-alpha.4.sql | 15 +++++++++++++++ 7 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 deploy/kakeibo.transactions@v1.0.0-alpha.4.sql create mode 100644 revert/kakeibo.transactions@v1.0.0-alpha.4.sql create mode 100644 verify/kakeibo.transactions@v1.0.0-alpha.4.sql diff --git a/deploy/kakeibo.transactions.sql b/deploy/kakeibo.transactions.sql index 0572a23..6e0787f 100644 --- a/deploy/kakeibo.transactions.sql +++ b/deploy/kakeibo.transactions.sql @@ -2,11 +2,14 @@ -- requires: schema -- requires: articles + BEGIN; +ALTER TABLE kakeibo.transactions RENAME COLUMN type_code TO type; ALTER TABLE kakeibo.transactions - ADD COLUMN article_id INTEGER, - ADD CONSTRAINT transactions_article_id_fkey - FOREIGN KEY (article_id) REFERENCES kakeibo.articles (id); + ALTER COLUMN type TYPE kakeibo.transaction_type + USING CASE type WHEN 0 + THEN 'outgo'::kakeibo.transaction_type + ELSE 'income'::kakeibo.transaction_type END; COMMIT; diff --git a/deploy/kakeibo.transactions@v1.0.0-alpha.4.sql b/deploy/kakeibo.transactions@v1.0.0-alpha.4.sql new file mode 100644 index 0000000..0572a23 --- /dev/null +++ b/deploy/kakeibo.transactions@v1.0.0-alpha.4.sql @@ -0,0 +1,12 @@ +-- Deploy kakeibo:transactions to pg +-- requires: schema +-- requires: articles + +BEGIN; + +ALTER TABLE kakeibo.transactions + ADD COLUMN article_id INTEGER, + ADD CONSTRAINT transactions_article_id_fkey + FOREIGN KEY (article_id) REFERENCES kakeibo.articles (id); + +COMMIT; diff --git a/revert/kakeibo.transactions.sql b/revert/kakeibo.transactions.sql index d30390a..a31898f 100644 --- a/revert/kakeibo.transactions.sql +++ b/revert/kakeibo.transactions.sql @@ -1,8 +1,12 @@ --- Revert kakeibo:transactions from pg +-- Deploy kakeibo:transactions to pg +-- requires: schema +-- requires: articles BEGIN; +ALTER TABLE kakeibo.transactions RENAME COLUMN type TO type_code; ALTER TABLE kakeibo.transactions - DROP COLUMN article_id; + ALTER COLUMN type_code TYPE integer + USING CASE type_code WHEN 'outgo' THEN 0 ELSE 1 END; COMMIT; diff --git a/revert/kakeibo.transactions@v1.0.0-alpha.4.sql b/revert/kakeibo.transactions@v1.0.0-alpha.4.sql new file mode 100644 index 0000000..d30390a --- /dev/null +++ b/revert/kakeibo.transactions@v1.0.0-alpha.4.sql @@ -0,0 +1,8 @@ +-- Revert kakeibo:transactions from pg + +BEGIN; + +ALTER TABLE kakeibo.transactions + DROP COLUMN article_id; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index 54ded53..f353f40 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -29,3 +29,4 @@ photo.photos [photo] 2023-03-27T16:00:51Z Masaya Tojo # Add @v1.0.0-alpha.4 2023-04-08T04:58:15Z Masaya Tojo # Tag v1.0.0-alpha.4 kakeibo.transaction_type [kakeibo] 2023-04-08T05:28:15Z Masaya Tojo # Add `transaction_type` enum type. +kakeibo.transactions [kakeibo.transactions@v1.0.0-alpha.4 kakeibo.transaction_type] 2023-04-08T05:50:31Z Masaya Tojo # Rename type_code column to type and change data type from integer to transaction_type. diff --git a/verify/kakeibo.transactions.sql b/verify/kakeibo.transactions.sql index 3f5b58f..3dc2a9a 100644 --- a/verify/kakeibo.transactions.sql +++ b/verify/kakeibo.transactions.sql @@ -3,7 +3,7 @@ BEGIN; SELECT id, - type_code, + type, date, note, created_at, diff --git a/verify/kakeibo.transactions@v1.0.0-alpha.4.sql b/verify/kakeibo.transactions@v1.0.0-alpha.4.sql new file mode 100644 index 0000000..3f5b58f --- /dev/null +++ b/verify/kakeibo.transactions@v1.0.0-alpha.4.sql @@ -0,0 +1,15 @@ +-- Verify kakeibo:transactions on pg + +BEGIN; + +SELECT id, + type_code, + date, + note, + created_at, + updated_at, + article_id + FROM kakeibo.transactions + WHERE FALSE; + +ROLLBACK; -- cgit v1.2.3