feat: add categories
This commit is contained in:
parent
c639f9800e
commit
a2b0ee5c15
2 changed files with 32 additions and 0 deletions
24
internal/db/migrations/00005_create_categories_tables.sql
Normal file
24
internal/db/migrations/00005_create_categories_tables.sql
Normal 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
|
||||
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue