diff --git a/internal/db/migrations/00005_create_categories_tables.sql b/internal/db/migrations/00005_create_categories_tables.sql new file mode 100644 index 0000000..695d06d --- /dev/null +++ b/internal/db/migrations/00005_create_categories_tables.sql @@ -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 diff --git a/internal/model/financial_management.go b/internal/model/financial_management.go index 07320da..b48bf7c 100644 --- a/internal/model/financial_management.go +++ b/internal/model/financial_management.go @@ -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"` +}