Skip to content

Commit

Permalink
fix: after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Nov 27, 2024
1 parent 64bad33 commit 2e50464
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 330 deletions.
3 changes: 0 additions & 3 deletions internal/storage/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (
"go.opentelemetry.io/otel/trace/noop"
)

// migration 23 (+1 regarding directory name, as migrations start from 1 in the lib)
const MinimalSchemaVersion = 24

type Bucket interface {
Migrate(ctx context.Context, minimalVersionReached chan struct{}, opts ...migrations.Option) error
AddLedger(ctx context.Context, ledger ledger.Ledger) error
Expand Down
10 changes: 5 additions & 5 deletions internal/storage/bucket/default_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
)

// stateless version (+1 regarding directory name, as migrations start from 1 in the lib)
const MinimalSchemaVersion = 12
const MinimalSchemaVersion = 24

type DefaultBucket struct {
name string
db *bun.DB
name string
db *bun.DB
tracer trace.Tracer
}

Expand Down Expand Up @@ -69,8 +69,8 @@ func (b *DefaultBucket) AddLedger(ctx context.Context, l ledger.Ledger) error {

func NewDefault(db *bun.DB, tracer trace.Tracer, name string) *DefaultBucket {
return &DefaultBucket{
db: db,
name: name,
db: db,
name: name,
tracer: tracer,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ drop function revert_transaction(_ledger character varying, _id numeric, _date t

drop index transactions_sources_arrays;
drop index transactions_destinations_arrays;
drop index accounts_address_array;
drop index accounts_address_array_length;
drop index transactions_sources;
drop index transactions_destinations;

Expand Down
10 changes: 2 additions & 8 deletions internal/storage/driver/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package driver

import (
"context"
"fmt"
ledgerstore "github.com/formancehq/ledger/internal/storage/ledger/legacy"
ledgerstore "github.com/formancehq/ledger/internal/storage/ledger"

ledger "github.com/formancehq/ledger/internal"
ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger"
Expand All @@ -20,12 +19,7 @@ func (d *DefaultStorageDriverAdapter) OpenLedger(ctx context.Context, name strin
return nil, nil, err
}

isUpToDate, err := store.GetBucket().IsUpToDate(ctx)
if err != nil {
return nil, nil, fmt.Errorf("checking if bucket is up to date: %w", err)
}

return ledgerstore.NewDefaultStoreAdapter(isUpToDate, store), l, nil
return ledgerstore.NewDefaultStoreAdapter(store), l, nil
}

func (d *DefaultStorageDriverAdapter) CreateLedger(ctx context.Context, l *ledger.Ledger) error {
Expand Down
2 changes: 0 additions & 2 deletions internal/storage/ledger/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"context"
"database/sql"
ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger"
"github.com/uptrace/bun"
)

type TX struct {
*Store
sqlTX bun.Tx
}

type DefaultStoreAdapter struct {
Expand Down
51 changes: 0 additions & 51 deletions internal/storage/ledger/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package ledger_test

import (
"database/sql"
"github.com/formancehq/go-libs/v2/bun/bunpaginate"
"math/big"
"testing"

Expand Down Expand Up @@ -156,56 +155,6 @@ func TestBalancesGet(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 2, count)
})

t.Run("with balance from move", func(t *testing.T) {
t.Parallel()

tx := ledger.NewTransaction().WithPostings(
ledger.NewPosting("world", "bank", "USD", big.NewInt(100)),
)
err := store.InsertTransaction(ctx, &tx)
require.NoError(t, err)

bankAccount := ledger.Account{
Address: "bank",
FirstUsage: tx.InsertedAt,
InsertionDate: tx.InsertedAt,
UpdatedAt: tx.InsertedAt,
}
err = store.UpsertAccounts(ctx, &bankAccount)
require.NoError(t, err)

err = store.InsertMoves(ctx, &ledger.Move{
TransactionID: tx.ID,
IsSource: false,
Account: "bank",
Amount: (*bunpaginate.BigInt)(big.NewInt(100)),
Asset: "USD",
InsertionDate: tx.InsertedAt,
EffectiveDate: tx.InsertedAt,
PostCommitVolumes: pointer.For(ledger.NewVolumesInt64(100, 0)),
})
require.NoError(t, err)

balances, err := store.GetBalances(ctx, ledgercontroller.BalanceQuery{
"bank": {"USD"},
})
require.NoError(t, err)

require.NotNil(t, balances["bank"])
RequireEqual(t, big.NewInt(100), balances["bank"]["USD"])

// Check a new line has been inserted into accounts_volumes table
volumes := &ledger.AccountsVolumes{}
err = store.GetDB().NewSelect().
ModelTableExpr(store.GetPrefixedRelationName("accounts_volumes")).
Where("accounts_address = ? and ledger = ?", "bank", store.GetLedger().Name).
Scan(ctx, volumes)
require.NoError(t, err)

RequireEqual(t, big.NewInt(100), volumes.Input)
RequireEqual(t, big.NewInt(0), volumes.Output)
})
}

func TestBalancesAggregates(t *testing.T) {
Expand Down
180 changes: 0 additions & 180 deletions internal/storage/ledger/legacy/adapters.go

This file was deleted.

Loading

0 comments on commit 2e50464

Please sign in to comment.