From c06e92662730e09cc2858e5d847a1d7184d51eed Mon Sep 17 00:00:00 2001 From: jethro Date: Wed, 13 May 2026 19:01:06 +1200 Subject: [PATCH] added some more tables for the db schema after discovering ideas while coding --- sql/database definitions.sql | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/sql/database definitions.sql b/sql/database definitions.sql index c21d827..6599832 100644 --- a/sql/database definitions.sql +++ b/sql/database definitions.sql @@ -17,4 +17,39 @@ description VARCHAR NOT NULL, amount REAL NOT NULL, accountid INT NOT NULL --foreign key from accounts orgid INT NOT NULL --foreign key from organizations -) \ No newline at end of file +) + +CREATE TABLE IF NOT EXISTS snapshots( +id SERIAL PRIMARY KEY, +datetime DATE NOT NULL, +accountid INT NOT NULL, --foreign key from accounts +balance REAL NOT NULL, +orgid INT NOT NULL --foreign key from organizations +) + +CREATE TABLE IF NOT EXISTS syncs( +id SERIAL PRIMARY KEY, +datetime DATE NOT NULL, +accountid INT NOT NULL, --foreign key from accounts +orgid INT NOT NULL --foreign key from organizations +) + +CREATE TABLE IF NOT EXISTS vendors( +id SERIAL PRIMARY KEY, +vendorname VARCHAR NOT NULL, +) + +CREATE TABLE IF NOT EXISTS rawtransactions( +id SERIAL PRIMARY KEY, +data JSONB NOT NULL, +received_at TIMESTAMPTZ NOT NULL DEFAULT now(), +source VARCHAR(100), +accountid INT REFERENCES accounts(id) ON DELETE SET NULL, +orgid INT REFERENCES organizations(id) ON DELETE SET NULL, +raw_sha256 CHAR(64) UNIQUE, +processed BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE INDEX IF NOT EXISTS rawtransactions_data_idx ON rawtransactions USING GIN (data); +CREATE INDEX IF NOT EXISTS rawtransactions_received_at_idx ON rawtransactions (received_at); +CREATE INDEX IF NOT EXISTS rawtransactions_account_org_idx ON rawtransactions (orgid, accountid); \ No newline at end of file