diff --git a/pkg/storage/sqlstorage/driver.go b/pkg/storage/sqlstorage/driver.go index f0c11d9c7..0b5c44e2b 100644 --- a/pkg/storage/sqlstorage/driver.go +++ b/pkg/storage/sqlstorage/driver.go @@ -5,6 +5,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "sync" "github.com/formancehq/go-libs/logging" "github.com/huandu/go-sqlbuilder" @@ -102,6 +103,7 @@ type Driver struct { db DB systemSchema Schema registeredLedgers map[string]struct{} + lock sync.Mutex } func (d *Driver) GetSystemStore() storage.SystemStore { @@ -118,6 +120,9 @@ func (d *Driver) GetLedgerStore(ctx context.Context, name string, create bool) ( ctx, span := opentelemetry.Start(ctx, "Load store") defer span.End() + d.lock.Lock() + defer d.lock.Unlock() + var ( created bool schema Schema