From 951e827d204abc15e9b1fd8b272ae0703043d5d7 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sun, 9 Jan 2022 20:47:43 +0000 Subject: [PATCH] Add transfer_id --- postgres/models.go | 1 + postgres/schema/20220109_212800_add-transfer-id.sql | 6 ++++++ postgres/transactions.sql.go | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 postgres/schema/20220109_212800_add-transfer-id.sql diff --git a/postgres/models.go b/postgres/models.go index ed57572..00a569d 100644 --- a/postgres/models.go +++ b/postgres/models.go @@ -64,6 +64,7 @@ type Transaction struct { AccountID uuid.UUID CategoryID uuid.NullUUID PayeeID uuid.NullUUID + TransferID uuid.NullUUID } type TransactionsByMonth struct { diff --git a/postgres/schema/20220109_212800_add-transfer-id.sql b/postgres/schema/20220109_212800_add-transfer-id.sql new file mode 100644 index 0000000..1f7af36 --- /dev/null +++ b/postgres/schema/20220109_212800_add-transfer-id.sql @@ -0,0 +1,6 @@ +-- +goose Up +ALTER TABLE transactions ADD COLUMN + transfer_id uuid NULL REFERENCES transactions (id); + +-- +goose Down +ALTER TABLE transactions DROP COLUMN transfer_id; \ No newline at end of file diff --git a/postgres/transactions.sql.go b/postgres/transactions.sql.go index dfd568e..ee110fa 100644 --- a/postgres/transactions.sql.go +++ b/postgres/transactions.sql.go @@ -14,7 +14,7 @@ const createTransaction = `-- name: CreateTransaction :one INSERT INTO transactions (date, memo, amount, account_id, payee_id, category_id) VALUES ($1, $2, $3, $4, $5, $6) -RETURNING id, date, memo, amount, account_id, category_id, payee_id +RETURNING id, date, memo, amount, account_id, category_id, payee_id, transfer_id ` type CreateTransactionParams struct { @@ -44,6 +44,7 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa &i.AccountID, &i.CategoryID, &i.PayeeID, + &i.TransferID, ) return i, err } @@ -74,7 +75,7 @@ func (q *Queries) DeleteTransaction(ctx context.Context, id uuid.UUID) error { } const getTransaction = `-- name: GetTransaction :one -SELECT id, date, memo, amount, account_id, category_id, payee_id FROM transactions +SELECT id, date, memo, amount, account_id, category_id, payee_id, transfer_id FROM transactions WHERE id = $1 ` @@ -89,6 +90,7 @@ func (q *Queries) GetTransaction(ctx context.Context, id uuid.UUID) (Transaction &i.AccountID, &i.CategoryID, &i.PayeeID, + &i.TransferID, ) return i, err }