Add accounts & payees
This commit is contained in:
parent
6df72dc40d
commit
37d19733df
@ -9,18 +9,32 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Account struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
BudgetID uuid.UUID
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
type Budget struct {
|
type Budget struct {
|
||||||
Name string
|
Name string
|
||||||
LastModification sql.NullTime
|
LastModification sql.NullTime
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transaction struct {
|
type Payee struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
BudgetID uuid.UUID
|
BudgetID uuid.UUID
|
||||||
Date time.Time
|
Name string
|
||||||
Memo sql.NullString
|
}
|
||||||
Amount string
|
|
||||||
|
type Transaction struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
BudgetID uuid.UUID
|
||||||
|
Date time.Time
|
||||||
|
Memo sql.NullString
|
||||||
|
Amount string
|
||||||
|
AccountID uuid.UUID
|
||||||
|
PayeeID uuid.NullUUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
37
postgres/schema/0006_accounts.sql
Normal file
37
postgres/schema/0006_accounts.sql
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
-- +goose Up
|
||||||
|
CREATE TABLE accounts (
|
||||||
|
id uuid DEFAULT uuid_generate_v4() NOT NULL,
|
||||||
|
budget_id uuid NOT NULL,
|
||||||
|
name varchar(50) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE payees (
|
||||||
|
id uuid DEFAULT uuid_generate_v4() NOT NULL,
|
||||||
|
budget_id uuid NOT NULL,
|
||||||
|
name varchar(50) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
TRUNCATE TABLE transactions;
|
||||||
|
ALTER TABLE transactions ADD COLUMN account_id uuid NOT NULL;
|
||||||
|
ALTER TABLE transactions ADD COLUMN payee_id uuid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE "user_budgets" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
|
||||||
|
|
||||||
|
ALTER TABLE "user_budgets" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id");
|
||||||
|
|
||||||
|
ALTER TABLE "transactions" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");
|
||||||
|
|
||||||
|
ALTER TABLE "accounts" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id");
|
||||||
|
|
||||||
|
ALTER TABLE "categories" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id");
|
||||||
|
|
||||||
|
ALTER TABLE "assignments" ADD FOREIGN KEY ("category_id") REFERENCES "categories" ("id");
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE transactions DROP COLUMN account_id;
|
||||||
|
ALTER TABLE transactions DROP COLUMN payee_id;
|
||||||
|
|
||||||
|
DROP TABLE accounts;
|
||||||
|
DROP TABLE payees;
|
@ -15,7 +15,7 @@ const createTransaction = `-- name: CreateTransaction :one
|
|||||||
INSERT INTO transactions
|
INSERT INTO transactions
|
||||||
(budget_id, date, memo, amount)
|
(budget_id, date, memo, amount)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id, budget_id, date, memo, amount
|
RETURNING id, budget_id, date, memo, amount, account_id, payee_id
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateTransactionParams struct {
|
type CreateTransactionParams struct {
|
||||||
@ -39,12 +39,14 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
|
|||||||
&i.Date,
|
&i.Date,
|
||||||
&i.Memo,
|
&i.Memo,
|
||||||
&i.Amount,
|
&i.Amount,
|
||||||
|
&i.AccountID,
|
||||||
|
&i.PayeeID,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
|
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
|
||||||
SELECT transactions.id, transactions.budget_id, transactions.date, transactions.memo, transactions.amount FROM transactions
|
SELECT transactions.id, transactions.budget_id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.payee_id FROM transactions
|
||||||
WHERE transactions.budget_id = $1
|
WHERE transactions.budget_id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -63,6 +65,8 @@ func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UU
|
|||||||
&i.Date,
|
&i.Date,
|
||||||
&i.Memo,
|
&i.Memo,
|
||||||
&i.Amount,
|
&i.Amount,
|
||||||
|
&i.AccountID,
|
||||||
|
&i.PayeeID,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user