diff --git a/internal/storage/bucket/bucket.go b/internal/storage/bucket/bucket.go index 8db0c7dda..32545970a 100644 --- a/internal/storage/bucket/bucket.go +++ b/internal/storage/bucket/bucket.go @@ -13,7 +13,7 @@ import ( ) // stateless version (+1 regarding directory name, as migrations start from 1 in the lib) -const MinimalSchemaVersion = 12 +const MinimalSchemaVersion = 15 type Bucket struct { name string diff --git a/internal/storage/bucket/migrations/11-make-stateless/up.sql b/internal/storage/bucket/migrations/11-make-stateless/up.sql index 182ce53b4..251d1448a 100644 --- a/internal/storage/bucket/migrations/11-make-stateless/up.sql +++ b/internal/storage/bucket/migrations/11-make-stateless/up.sql @@ -200,8 +200,6 @@ execute procedure set_compat_on_transactions_metadata(); alter table transactions add column post_commit_volumes jsonb, --- todo: set in subsequent migration `default transaction_date()`, --- otherwise the function is called for every existing lines add column inserted_at timestamp without time zone, alter column timestamp set default transaction_date() -- todo: we should change the type of this column, but actually it cause a full lock of the table @@ -363,7 +361,6 @@ from (select row_number() over () as number, v.value select null) v) data $$ set search_path from current; --- todo(next-minor): remove that on future version when the table will have this default value (need to fill nulls before) create or replace function set_transaction_inserted_at() returns trigger security definer language plpgsql diff --git a/internal/storage/bucket/migrations/12-moves-fill-transaction-id/notes.yaml b/internal/storage/bucket/migrations/16-moves-fill-transaction-id/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/12-moves-fill-transaction-id/notes.yaml rename to internal/storage/bucket/migrations/16-moves-fill-transaction-id/notes.yaml diff --git a/internal/storage/bucket/migrations/12-moves-fill-transaction-id/up.sql b/internal/storage/bucket/migrations/16-moves-fill-transaction-id/up.sql similarity index 100% rename from internal/storage/bucket/migrations/12-moves-fill-transaction-id/up.sql rename to internal/storage/bucket/migrations/16-moves-fill-transaction-id/up.sql diff --git a/internal/storage/bucket/migrations/12-moves-fill-transaction-id/up_tests_after.sql b/internal/storage/bucket/migrations/16-moves-fill-transaction-id/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/12-moves-fill-transaction-id/up_tests_after.sql rename to internal/storage/bucket/migrations/16-moves-fill-transaction-id/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/12-moves-fill-transaction-id/up_tests_before.sql b/internal/storage/bucket/migrations/16-moves-fill-transaction-id/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/12-moves-fill-transaction-id/up_tests_before.sql rename to internal/storage/bucket/migrations/16-moves-fill-transaction-id/up_tests_before.sql diff --git a/internal/storage/bucket/migrations/13-transactions-fill-inserted-at/notes.yaml b/internal/storage/bucket/migrations/17-transactions-fill-inserted-at/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/13-transactions-fill-inserted-at/notes.yaml rename to internal/storage/bucket/migrations/17-transactions-fill-inserted-at/notes.yaml diff --git a/internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up.sql b/internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up.sql similarity index 87% rename from internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up.sql rename to internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up.sql index d7e500d80..6adca135f 100644 --- a/internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up.sql +++ b/internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up.sql @@ -49,5 +49,11 @@ do $$ end loop; drop table logs_transactions; + + alter table transactions + alter column inserted_at set default transaction_date(); + + drop trigger set_transaction_inserted_at on transactions; + drop function set_transaction_inserted_at; end $$; \ No newline at end of file diff --git a/internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up_tests_after.sql b/internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up_tests_after.sql rename to internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up_tests_before.sql b/internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/13-transactions-fill-inserted-at/up_tests_before.sql rename to internal/storage/bucket/migrations/17-transactions-fill-inserted-at/up_tests_before.sql diff --git a/internal/storage/bucket/migrations/14-transactions-fill-pcv/notes.yaml b/internal/storage/bucket/migrations/18-transactions-fill-pcv/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/14-transactions-fill-pcv/notes.yaml rename to internal/storage/bucket/migrations/18-transactions-fill-pcv/notes.yaml diff --git a/internal/storage/bucket/migrations/14-transactions-fill-pcv/up.sql b/internal/storage/bucket/migrations/18-transactions-fill-pcv/up.sql similarity index 100% rename from internal/storage/bucket/migrations/14-transactions-fill-pcv/up.sql rename to internal/storage/bucket/migrations/18-transactions-fill-pcv/up.sql diff --git a/internal/storage/bucket/migrations/14-transactions-fill-pcv/up_tests_after.sql b/internal/storage/bucket/migrations/18-transactions-fill-pcv/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/14-transactions-fill-pcv/up_tests_after.sql rename to internal/storage/bucket/migrations/18-transactions-fill-pcv/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/14-transactions-fill-pcv/up_tests_before.sql b/internal/storage/bucket/migrations/18-transactions-fill-pcv/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/14-transactions-fill-pcv/up_tests_before.sql rename to internal/storage/bucket/migrations/18-transactions-fill-pcv/up_tests_before.sql diff --git a/internal/storage/bucket/migrations/15-accounts-volumes-fill-history/notes.yaml b/internal/storage/bucket/migrations/19-accounts-volumes-fill-history/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/15-accounts-volumes-fill-history/notes.yaml rename to internal/storage/bucket/migrations/19-accounts-volumes-fill-history/notes.yaml diff --git a/internal/storage/bucket/migrations/15-accounts-volumes-fill-history/up.sql b/internal/storage/bucket/migrations/19-accounts-volumes-fill-history/up.sql similarity index 100% rename from internal/storage/bucket/migrations/15-accounts-volumes-fill-history/up.sql rename to internal/storage/bucket/migrations/19-accounts-volumes-fill-history/up.sql diff --git a/internal/storage/bucket/migrations/15-accounts-volumes-fill-history/up_tests_after.sql b/internal/storage/bucket/migrations/19-accounts-volumes-fill-history/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/15-accounts-volumes-fill-history/up_tests_after.sql rename to internal/storage/bucket/migrations/19-accounts-volumes-fill-history/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/15-accounts-volumes-fill-history/up_tests_before.sql b/internal/storage/bucket/migrations/19-accounts-volumes-fill-history/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/15-accounts-volumes-fill-history/up_tests_before.sql rename to internal/storage/bucket/migrations/19-accounts-volumes-fill-history/up_tests_before.sql diff --git a/internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/notes.yaml b/internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/notes.yaml rename to internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/notes.yaml diff --git a/internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/up.sql b/internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/up.sql similarity index 100% rename from internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/up.sql rename to internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/up.sql diff --git a/internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/up_tests_after.sql b/internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/up_tests_after.sql rename to internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/up_tests_before.sql b/internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/16-transactions-metadata-fill-transaction-id/up_tests_before.sql rename to internal/storage/bucket/migrations/20-transactions-metadata-fill-transaction-id/up_tests_before.sql diff --git a/internal/storage/bucket/migrations/17-accounts-metadata-fill-address/notes.yaml b/internal/storage/bucket/migrations/21-accounts-metadata-fill-address/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/17-accounts-metadata-fill-address/notes.yaml rename to internal/storage/bucket/migrations/21-accounts-metadata-fill-address/notes.yaml diff --git a/internal/storage/bucket/migrations/17-accounts-metadata-fill-address/up.sql b/internal/storage/bucket/migrations/21-accounts-metadata-fill-address/up.sql similarity index 100% rename from internal/storage/bucket/migrations/17-accounts-metadata-fill-address/up.sql rename to internal/storage/bucket/migrations/21-accounts-metadata-fill-address/up.sql diff --git a/internal/storage/bucket/migrations/17-accounts-metadata-fill-address/up_tests_after.sql b/internal/storage/bucket/migrations/21-accounts-metadata-fill-address/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/17-accounts-metadata-fill-address/up_tests_after.sql rename to internal/storage/bucket/migrations/21-accounts-metadata-fill-address/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/17-accounts-metadata-fill-address/up_tests_before.sql b/internal/storage/bucket/migrations/21-accounts-metadata-fill-address/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/17-accounts-metadata-fill-address/up_tests_before.sql rename to internal/storage/bucket/migrations/21-accounts-metadata-fill-address/up_tests_before.sql diff --git a/internal/storage/bucket/migrations/18-logs-fill-memento/notes.yaml b/internal/storage/bucket/migrations/22-logs-fill-memento/notes.yaml similarity index 100% rename from internal/storage/bucket/migrations/18-logs-fill-memento/notes.yaml rename to internal/storage/bucket/migrations/22-logs-fill-memento/notes.yaml diff --git a/internal/storage/bucket/migrations/18-logs-fill-memento/up.sql b/internal/storage/bucket/migrations/22-logs-fill-memento/up.sql similarity index 100% rename from internal/storage/bucket/migrations/18-logs-fill-memento/up.sql rename to internal/storage/bucket/migrations/22-logs-fill-memento/up.sql diff --git a/internal/storage/bucket/migrations/18-logs-fill-memento/up_tests_after.sql b/internal/storage/bucket/migrations/22-logs-fill-memento/up_tests_after.sql similarity index 100% rename from internal/storage/bucket/migrations/18-logs-fill-memento/up_tests_after.sql rename to internal/storage/bucket/migrations/22-logs-fill-memento/up_tests_after.sql diff --git a/internal/storage/bucket/migrations/18-logs-fill-memento/up_tests_before.sql b/internal/storage/bucket/migrations/22-logs-fill-memento/up_tests_before.sql similarity index 100% rename from internal/storage/bucket/migrations/18-logs-fill-memento/up_tests_before.sql rename to internal/storage/bucket/migrations/22-logs-fill-memento/up_tests_before.sql diff --git a/internal/storage/ledger/transactions.go b/internal/storage/ledger/transactions.go index a8b522e7d..e08d573a7 100644 --- a/internal/storage/ledger/transactions.go +++ b/internal/storage/ledger/transactions.go @@ -401,11 +401,6 @@ func (s *Store) InsertTransaction(ctx context.Context, tx *ledger.Transaction) e if err.(postgres.ErrConstraintsFailed).GetConstraint() == "transactions_reference" { return nil, ledgercontroller.NewErrTransactionReferenceConflict(tx.Reference) } - case errors.Is(err, postgres.ErrRaisedException{}): - // todo(next-minor): remove this test - if err.(postgres.ErrRaisedException).GetMessage() == "duplicate reference" { - return nil, ledgercontroller.NewErrTransactionReferenceConflict(tx.Reference) - } default: return nil, err } diff --git a/internal/storage/ledger/transactions_test.go b/internal/storage/ledger/transactions_test.go index 6bb0312e3..469804f65 100644 --- a/internal/storage/ledger/transactions_test.go +++ b/internal/storage/ledger/transactions_test.go @@ -7,9 +7,6 @@ import ( "database/sql" "fmt" "github.com/alitto/pond" - "github.com/formancehq/ledger/internal/storage/bucket" - ledgerstore "github.com/formancehq/ledger/internal/storage/ledger" - "github.com/google/uuid" "math/big" "slices" "testing" @@ -606,84 +603,6 @@ func TestTransactionsInsert(t *testing.T) { require.Error(t, err) require.True(t, errors.Is(err, ledgercontroller.ErrTransactionReferenceConflict{})) }) - // todo(next-minor): remove this test - t.Run("check reference conflict with minimal store version", func(t *testing.T) { - t.Parallel() - - driver := newDriver(t) - ledgerName := uuid.NewString()[:8] - - l := ledger.MustNewWithDefault(ledgerName) - l.Bucket = ledgerName - - migrator := bucket.GetMigrator(driver.GetDB(), ledgerName) - for i := 0; i < bucket.MinimalSchemaVersion; i++ { - require.NoError(t, migrator.UpByOne(ctx)) - } - - b := bucket.New(driver.GetDB(), ledgerName) - err := b.AddLedger(ctx, l, driver.GetDB()) - require.NoError(t, err) - - store := ledgerstore.New(driver.GetDB(), b, l) - - const nbTry = 100 - - for i := 0; i < nbTry; i++ { - errChan := make(chan error, 2) - - // Create a simple tx - tx1 := ledger.Transaction{ - TransactionData: ledger.TransactionData{ - Timestamp: now, - Reference: fmt.Sprintf("foo:%d", i), - Postings: []ledger.Posting{ - ledger.NewPosting("world", "bank", "USD/2", big.NewInt(100)), - }, - }, - } - go func() { - errChan <- store.InsertTransaction(ctx, &tx1) - }() - - // Create another tx with the same reference - tx2 := ledger.Transaction{ - TransactionData: ledger.TransactionData{ - Timestamp: now, - Reference: fmt.Sprintf("foo:%d", i), - Postings: []ledger.Posting{ - ledger.NewPosting("world", "bank", "USD/2", big.NewInt(100)), - }, - }, - } - go func() { - errChan <- store.InsertTransaction(ctx, &tx2) - }() - - select { - case err1 := <-errChan: - if err1 != nil { - require.True(t, errors.Is(err1, ledgercontroller.ErrTransactionReferenceConflict{})) - select { - case err2 := <-errChan: - require.NoError(t, err2) - case <-time.After(time.Second): - require.Fail(t, "should have received an error") - } - } else { - select { - case err2 := <-errChan: - require.Error(t, err2) - require.True(t, errors.Is(err2, ledgercontroller.ErrTransactionReferenceConflict{})) - case <-time.After(time.Second): - require.Fail(t, "should have received an error") - } - } - case <-time.After(time.Second): - require.Fail(t, "should have received an error") - } - } - }) t.Run("check denormalization", func(t *testing.T) { t.Parallel()