What changed, and why it matters
This commit is a routine code cleanup in LND's database migration system. It narrows a Go interface so that production code only exposes the migration method actually needed at runtime, while test-only helpers move to the concrete database types. There is no security-relevant change: no bug is fixed, no vulnerability is introduced, and no behavior of the running program changes.
No action required. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors sqldb/v2’s MigrationExecutor interface. It removes SkipMigrations(), DefaultTarget(), GetSchemaVersion(), and SetSchemaVersion() from the interface and folds the first two into ExecuteMigrations on the concrete PostgresStore and SqliteStore types. Test helpers now call a new unexported executeMigrations method directly on the concrete types. The production migration path still checks SkipMigrations and runs to the latest target exactly as before; only the API surface changed.
Changed components
sqldb/v2/migrations.gosqldb/v2/postgres.gosqldb/v2/postgres_fixture.gosqldb/v2/sqlite.gosqldb/v2/sqlite_test_utils.goInspect captured patch +33 / −52
diff --git a/sqldb/v2/migrations.go b/sqldb/v2/migrations.go
index 538abe2..56e0f3c 100644
--- a/sqldb/v2/migrations.go
+++ b/sqldb/v2/migrations.go
@@ -96,29 +96,11 @@ type MigrationTarget func(mig *migrate.Migrate,
// MigrationExecutor is an interface that abstracts the migration functionality.
type MigrationExecutor interface {
- // ExecuteMigrations runs database migrations up to the specified target
- // version or all migrations if no target is specified. A migration may
- // include a schema change, a custom migration function, or both.
- // Developers must ensure that migrations are defined in the correct
- // order. Migration details are stored in the global variable
- // migrationConfig.
- ExecuteMigrations(target MigrationTarget, set MigrationSet) error
-
- // GetSchemaVersion returns the current schema version of the database.
- GetSchemaVersion() (int, bool, error)
-
- // SetSchemaVersion sets the schema version of the database.
- //
- // NOTE: This alters the internal database schema tracker. USE WITH
- // CAUTION!!!
- SetSchemaVersion(version int, dirty bool) error
-
- // DefaultTarget returns the default migration target.
- DefaultTarget() MigrationTarget
-
- // SkipMigrations indicates if the SQL and corresponding code migrations
- // will be skipped.
- SkipMigrations() bool
+ // ExecuteMigrations runs database migrations for the given migration
+ // set using the executor's default production migration target. A
+ // migration may include a schema change, a custom migration function,
+ // or both.
+ ExecuteMigrations(set MigrationSet) error
}
var (
@@ -403,13 +385,8 @@ func (t *replacerFile) Close() error {
// ApplyAllMigrations applies both the SQLC and custom in-code migrations to the
// SQLite database.
func ApplyAllMigrations(executor MigrationExecutor, sets []MigrationSet) error {
- // Execute migrations unless configured to skip them.
- if executor.SkipMigrations() {
- return nil
- }
-
for _, set := range sets {
- err := executor.ExecuteMigrations(executor.DefaultTarget(), set)
+ err := executor.ExecuteMigrations(set)
if err != nil {
return fmt.Errorf("error applying migrations: %w", err)
}
diff --git a/sqldb/v2/postgres.go b/sqldb/v2/postgres.go
index 3b0255a..35fa513 100644
--- a/sqldb/v2/postgres.go
+++ b/sqldb/v2/postgres.go
@@ -167,9 +167,19 @@ func errPostgresMigration(err error) error {
return fmt.Errorf("error creating postgres migration: %w", err)
}
-// ExecuteMigrations runs migrations for the Postgres database, depending on the
-// target given, either all migrations or up to a given version.
-func (s *PostgresStore) ExecuteMigrations(target MigrationTarget,
+// ExecuteMigrations runs migrations for the Postgres database using the
+// default production migration target.
+func (s *PostgresStore) ExecuteMigrations(set MigrationSet) error {
+ if s.cfg.SkipMigrations {
+ return nil
+ }
+
+ return s.executeMigrations(TargetLatest, set)
+}
+
+// executeMigrations runs migrations for the Postgres database, depending on
+// the target given, either all migrations or up to a given version.
+func (s *PostgresStore) executeMigrations(target MigrationTarget,
set MigrationSet) error {
dbName, err := getDatabaseNameFromDSN(s.cfg.Dsn)
@@ -231,11 +241,3 @@ func (s *PostgresStore) SetSchemaVersion(version int, dirty bool) error {
return driver.SetVersion(version, dirty)
}
-
-func (s *PostgresStore) DefaultTarget() MigrationTarget {
- return TargetLatest
-}
-
-func (s *PostgresStore) SkipMigrations() bool {
- return s.cfg.SkipMigrations
-}
diff --git a/sqldb/v2/postgres_fixture.go b/sqldb/v2/postgres_fixture.go
index 8d653af..cf11154 100644
--- a/sqldb/v2/postgres_fixture.go
+++ b/sqldb/v2/postgres_fixture.go
@@ -197,7 +197,7 @@ func NewTestPostgresDBWithVersion(t testing.TB, fixture *TestPgFixture,
store, err := NewPostgresStore(storeCfg)
require.NoError(t, err)
- err = store.ExecuteMigrations(TargetVersion(version), sets)
+ err = store.executeMigrations(TargetVersion(version), sets)
require.NoError(t, err)
t.Cleanup(func() {
diff --git a/sqldb/v2/sqlite.go b/sqldb/v2/sqlite.go
index 7cd12c1..b988a72 100644
--- a/sqldb/v2/sqlite.go
+++ b/sqldb/v2/sqlite.go
@@ -251,9 +251,19 @@ func (s *SqliteStore) backupAndMigrate(mig *migrate.Migrate,
return mig.Up()
}
-// ExecuteMigrations runs migrations for the sqlite database, depending on the
+// ExecuteMigrations runs migrations for the sqlite database using the default
+// production migration target.
+func (s *SqliteStore) ExecuteMigrations(set MigrationSet) error {
+ if s.Config.SkipMigrations {
+ return nil
+ }
+
+ return s.executeMigrations(s.backupAndMigrate, set)
+}
+
+// executeMigrations runs migrations for the sqlite database, depending on the
// target given, either all migrations or up to a given version.
-func (s *SqliteStore) ExecuteMigrations(target MigrationTarget,
+func (s *SqliteStore) executeMigrations(target MigrationTarget,
set MigrationSet) error {
driver, err := sqlite_migrate.WithInstance(
@@ -285,14 +295,6 @@ func (s *SqliteStore) ExecuteMigrations(target MigrationTarget,
)
}
-func (s *SqliteStore) DefaultTarget() MigrationTarget {
- return s.backupAndMigrate
-}
-
-func (s *SqliteStore) SkipMigrations() bool {
- return s.Config.SkipMigrations
-}
-
// GetSchemaVersion returns the current schema version of the SQLite database.
func (s *SqliteStore) GetSchemaVersion() (int, bool, error) {
driver, err := sqlite_migrate.WithInstance(
diff --git a/sqldb/v2/sqlite_test_utils.go b/sqldb/v2/sqlite_test_utils.go
index 849fbae..03ef833 100644
--- a/sqldb/v2/sqlite_test_utils.go
+++ b/sqldb/v2/sqlite_test_utils.go
@@ -75,7 +75,7 @@ func NewTestSqliteDBWithVersion(t *testing.T, set MigrationSet,
}, dbFileName)
require.NoError(t, err)
- err = sqlDB.ExecuteMigrations(TargetVersion(version), set)
+ err = sqlDB.executeMigrations(TargetVersion(version), set)
require.NoError(t, err)
t.Cleanup(func() {
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.