sqldb: separate migration execution from construction

This commit separates the execution of SQL and in-code migrations
from their construction. This change is necessary because,
currently, the SQL schema is migrated during the construction
phase in the lncfg package. However, migrations are typically
executed when individual stores are constructed within the
configuration builder.
This commit is contained in:
Andras Banki-Horvath
2024-11-25 20:29:08 +01:00
parent b789fb2db3
commit 91c3e1496f
8 changed files with 137 additions and 57 deletions

View File

@@ -148,9 +148,13 @@ func NewTestPostgresDB(t *testing.T, fixture *TestPgFixture) *PostgresStore {
require.NoError(t, err)
cfg := fixture.GetConfig(dbName)
store, err := NewPostgresStore(cfg, GetMigrations())
store, err := NewPostgresStore(cfg)
require.NoError(t, err)
require.NoError(t, store.ApplyAllMigrations(
context.Background(), GetMigrations()),
)
return store
}
@@ -172,7 +176,7 @@ func NewTestPostgresDBWithVersion(t *testing.T, fixture *TestPgFixture,
storeCfg := fixture.GetConfig(dbName)
storeCfg.SkipMigrations = true
store, err := NewPostgresStore(storeCfg, GetMigrations())
store, err := NewPostgresStore(storeCfg)
require.NoError(t, err)
err = store.ExecuteMigrations(TargetVersion(version))