From a09ba8f530149b6dc210dc223df24220e801f2e1 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Sun, 13 Oct 2024 12:31:38 +0200 Subject: [PATCH] fix: remove duplicate date assignation --- internal/moves.go | 4 ++-- .../storage/bucket/migrations/33-moves-assign-date.sql | 4 ++++ internal/storage/ledger/accounts.go | 2 +- internal/storage/ledger/accounts_test.go | 2 +- internal/storage/ledger/transactions.go | 8 +++----- 5 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 internal/storage/bucket/migrations/33-moves-assign-date.sql diff --git a/internal/moves.go b/internal/moves.go index ebd930e4f..24eeedb24 100644 --- a/internal/moves.go +++ b/internal/moves.go @@ -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"` } diff --git a/internal/storage/bucket/migrations/33-moves-assign-date.sql b/internal/storage/bucket/migrations/33-moves-assign-date.sql new file mode 100644 index 000000000..51d2e467d --- /dev/null +++ b/internal/storage/bucket/migrations/33-moves-assign-date.sql @@ -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') +; \ No newline at end of file diff --git a/internal/storage/ledger/accounts.go b/internal/storage/ledger/accounts.go index b5d80e72c..51a7c65a5 100644 --- a/internal/storage/ledger/accounts.go +++ b/internal/storage/ledger/accounts.go @@ -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). diff --git a/internal/storage/ledger/accounts_test.go b/internal/storage/ledger/accounts_test.go index fbc1b5241..e8d14614b 100644 --- a/internal/storage/ledger/accounts_test.go +++ b/internal/storage/ledger/accounts_test.go @@ -379,7 +379,7 @@ func TestAccountsUpsert(t *testing.T) { ctx := logging.TestingContext() account := ledger.Account{ - Address: "foo", + Address: "foo", } // Initial insert diff --git a/internal/storage/ledger/transactions.go b/internal/storage/ledger/transactions.go index 66e651a6c..dc3f214e4 100644 --- a/internal/storage/ledger/transactions.go +++ b/internal/storage/ledger/transactions.go @@ -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)