diff options
| author | Masaya Tojo <masaya@tojo.tokyo> | 2023-08-31 00:35:36 +0900 | 
|---|---|---|
| committer | Masaya Tojo <masaya@tojo.tokyo> | 2023-10-13 02:13:22 +0900 | 
| commit | e3131b37eb7d9b6284a68077a9f0d5ad9dc99f98 (patch) | |
| tree | 16bb962bbbe566b24e985c4886570d498a62c009 | |
| parent | 67cabf314b2b60c81454682f9259c3c207f71a73 (diff) | |
Add table to manage transactions
| -rw-r--r-- | deploy/transactions.sql | 20 | ||||
| -rw-r--r-- | revert/transactions.sql | 9 | ||||
| -rw-r--r-- | sqitch.plan | 1 | ||||
| -rw-r--r-- | verify/transactions.sql | 11 | 
4 files changed, 41 insertions, 0 deletions
diff --git a/deploy/transactions.sql b/deploy/transactions.sql new file mode 100644 index 0000000..3f21eb7 --- /dev/null +++ b/deploy/transactions.sql @@ -0,0 +1,20 @@ +-- Deploy photos:transactions to pg +-- requires: schema +-- requires: photos + +BEGIN; + +SET search_path to photos; + +CREATE TABLE transactions( +  id UUID PRIMARY KEY, +  photo_id UUID NOT NULL REFERENCES photos(id) ON DELETE RESTRICT ON UPDATE RESTRICT, +  is_income BOOLEAN NOT NULL DEFAULT FALSE, +  category TEXT NOT NULL CHECK (category <> ''), +  amount INTEGER NOT NULL CHECK (amount > 0), +  note TEXT CHECK (note <> ''), +  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), +  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +COMMIT; diff --git a/revert/transactions.sql b/revert/transactions.sql new file mode 100644 index 0000000..273d149 --- /dev/null +++ b/revert/transactions.sql @@ -0,0 +1,9 @@ +-- Revert photos:transactions from pg + +BEGIN; + +SET search_path to photos; + +DROP TABLE transactions; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index ec8c6b8..dadb8a8 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -8,3 +8,4 @@ update_timestamp [schema] 2023-08-29T15:03:35Z Masaya Tojo <masaya@tojo.tokyo> #  photos_update_timestamp [schema photos update_timestamp] 2023-08-29T15:15:40Z Masaya Tojo <masaya@tojo.tokyo> # Add update_timestamp trigger to photos table  diaries [schema photos] 2023-08-29T15:30:42Z Masaya Tojo <masaya@tojo.tokyo> # Add table to manage diaries  diaries_update_timestamp [schema diaries update_timestamp] 2023-08-29T15:57:21Z Masaya Tojo <masaya@tojo.tokyo> # Add update_timestamp trigger to diaries table +transactions [schema photos] 2023-08-30T15:06:32Z Masaya Tojo <masaya@tojo.tokyo> # Add table to manage transactions diff --git a/verify/transactions.sql b/verify/transactions.sql new file mode 100644 index 0000000..1a01f6f --- /dev/null +++ b/verify/transactions.sql @@ -0,0 +1,11 @@ +-- Verify photos:transactions on pg + +BEGIN; + +SET search_path to photos; + +SELECT id, photo_id, is_income, category, amount, note, created_at, updated_at +  FROM transactions + WHERE FALSE; + +ROLLBACK;  | 
