feat: new minimal db schema

This commit is contained in:
juancwu 2026-04-06 14:49:36 +00:00
commit 7be5510753
21 changed files with 97 additions and 739 deletions

View file

@ -0,0 +1,44 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE accounts (
id TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
space_id TEXT NOT NULL REFERENCES spaces(id) ON DELETE CASCADE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE transactions (
id TEXT NOT NULL PRIMARY KEY,
value TEXT NOT NULL,
type TEXT NOT NULL,
account_id TEXT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
description TEXT,
related_transaction_id TEXT REFERENCES transactions(id) ON DELETE SET NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE tags (
id TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
space_id TEXT NOT NULL REFERENCES spaces(id) ON DELETE CASCADE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE transaction_tags (
tag_id TEXT NOT NULL REFERENCES tags(id) ON DELETE CASCADE,
transaction_id TEXT NOT NULL REFERENCES transactions(id) ON DELETE CASCADE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tag_id, transaction_id)
);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE transaction_tags;
DROP TABLE tags;
DROP TABLE transactions;
DROP TABLE accounts;
-- +goose StatementEnd