From e3131b37eb7d9b6284a68077a9f0d5ad9dc99f98 Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Thu, 31 Aug 2023 00:35:36 +0900
Subject: Add table to manage transactions

---
 deploy/transactions.sql | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 deploy/transactions.sql

(limited to 'deploy/transactions.sql')

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;
-- 
cgit v1.2.3

