Skip to content

Commit

Permalink
fix: remove duplicate date assignation
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 16, 2024
1 parent f2719e6 commit a09ba8f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/moves.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type Move struct {
Account string `bun:"accounts_address,type:varchar"`
Amount *bunpaginate.BigInt `bun:"amount,type:numeric"`
Asset string `bun:"asset,type:varchar"`
InsertionDate time.Time `bun:"insertion_date,type:timestamp"`
EffectiveDate time.Time `bun:"effective_date,type:timestamp"`
InsertionDate time.Time `bun:"insertion_date,type:timestamp,nullzero"`
EffectiveDate time.Time `bun:"effective_date,type:timestamp,nullzero"`
PostCommitVolumes *Volumes `bun:"post_commit_volumes,type:jsonb"`
PostCommitEffectiveVolumes *Volumes `bun:"post_commit_effective_volumes,type:jsonb,scanonly"`
}
Expand Down
4 changes: 4 additions & 0 deletions internal/storage/bucket/migrations/33-moves-assign-date.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alter table "{{.Bucket}}".moves
alter column insertion_date set default (now() at time zone 'utc'),
alter column effective_date set default (now() at time zone 'utc')
;
2 changes: 1 addition & 1 deletion internal/storage/ledger/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (s *Store) UpsertAccount(ctx context.Context, account *ledger.Account) (boo
On("conflict (ledger, address) do update").
Set("first_usage = case when ? < excluded.first_usage then ? else excluded.first_usage end", account.FirstUsage, account.FirstUsage).
Set("metadata = accounts.metadata || excluded.metadata").
Set("updated_at = ?", account.UpdatedAt).
Set("updated_at = excluded.updated_at").
Value("ledger", "?", s.ledger.Name).
Returning("*").
Where("(? < accounts.first_usage) or not accounts.metadata @> excluded.metadata", account.FirstUsage).
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/ledger/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func TestAccountsUpsert(t *testing.T) {
ctx := logging.TestingContext()

account := ledger.Account{
Address: "foo",
Address: "foo",
}

// Initial insert
Expand Down
8 changes: 3 additions & 5 deletions internal/storage/ledger/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,9 @@ func (s *Store) CommitTransaction(ctx context.Context, tx *ledger.Transaction) e

for _, address := range tx.InvolvedAccounts() {
_, err := s.UpsertAccount(ctx, &ledger.Account{
Address: address,
FirstUsage: tx.Timestamp,
InsertionDate: tx.InsertedAt,
UpdatedAt: tx.InsertedAt,
Metadata: make(metadata.Metadata),
Address: address,
FirstUsage: tx.Timestamp,
Metadata: make(metadata.Metadata),
})
if err != nil {
return fmt.Errorf("upserting account: %w", err)
Expand Down

0 comments on commit a09ba8f

Please sign in to comment.