mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-29 23:47:13 +01:00
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:
@@ -314,16 +314,19 @@ func TestCustomMigration(t *testing.T) {
|
||||
for i := 0; i < 3; i++ {
|
||||
db, err = NewSqliteStore(&SqliteConfig{
|
||||
SkipMigrations: false,
|
||||
}, dbFileName, test.migrations)
|
||||
if db != nil {
|
||||
dbToCleanup := db.DB
|
||||
t.Cleanup(func() {
|
||||
require.NoError(
|
||||
t, dbToCleanup.Close(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}, dbFileName)
|
||||
require.NoError(t, err)
|
||||
|
||||
dbToCleanup := db.DB
|
||||
t.Cleanup(func() {
|
||||
require.NoError(
|
||||
t, dbToCleanup.Close(),
|
||||
)
|
||||
})
|
||||
|
||||
err = db.ApplyAllMigrations(
|
||||
ctxb, test.migrations,
|
||||
)
|
||||
if test.expectedSuccess {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
@@ -333,7 +336,7 @@ func TestCustomMigration(t *testing.T) {
|
||||
// so we can read versions.
|
||||
db, err = NewSqliteStore(&SqliteConfig{
|
||||
SkipMigrations: true,
|
||||
}, dbFileName, nil)
|
||||
}, dbFileName)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -399,8 +402,12 @@ func TestCustomMigration(t *testing.T) {
|
||||
// are idempotent.
|
||||
for i := 0; i < 3; i++ {
|
||||
cfg.SkipMigrations = false
|
||||
db, err = NewPostgresStore(cfg, test.migrations)
|
||||
db, err = NewPostgresStore(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = db.ApplyAllMigrations(
|
||||
ctxb, test.migrations,
|
||||
)
|
||||
if test.expectedSuccess {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
@@ -409,7 +416,7 @@ func TestCustomMigration(t *testing.T) {
|
||||
// Also repoen the DB without migrations
|
||||
// so we can read versions.
|
||||
cfg.SkipMigrations = true
|
||||
db, err = NewPostgresStore(cfg, nil)
|
||||
db, err = NewPostgresStore(cfg)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user