feat: add categories

This commit is contained in:
juancwu 2026-04-11 19:12:19 +00:00
commit a2b0ee5c15
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,24 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE categories (
id TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE transaction_categories (
category_id TEXT NOT NULL REFERENCES categories(id) ON DELETE CASCADE,
transaction_id TEXT NOT NULL REFERENCES transactions(id) ON DELETE CASCADE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (category_id, transaction_id)
);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE transaction_categories;
DROP TABLE categories;
-- +goose StatementEnd

View file

@ -40,3 +40,11 @@ type Tag struct {
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type Category struct {
ID string `db:"id"`
Name string `db:"name"`
Description *string `db:"description"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}