db: remove kvdb to sql migration from dev db stream

Remove the KVDB-to-SQL migration from the dev SQL migration set now
that this migration is now part of the production migration set.

As the migrations_dev folder no longer contains any migrations, we also
update the db logic and the gen_sqlc_docker.sh script to not error when
the folder(s) are empty.
This commit is contained in:
Viktor Torstensson 2026-05-12 12:58:16 +02:00
parent 85d0739019
commit 10949c7bb8
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4
5 changed files with 30 additions and 23 deletions

View file

@ -1,6 +1,8 @@
package db package db
import ( import (
"io/fs"
"github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/pgx/v5" "github.com/golang-migrate/migrate/v4/database/pgx/v5"
"github.com/lightningnetwork/lnd/sqldb/v2" "github.com/lightningnetwork/lnd/sqldb/v2"
@ -28,9 +30,21 @@ const (
// //
// NOTE: This MUST be updated when a migration is added or removed, from // NOTE: This MUST be updated when a migration is added or removed, from
// the migrations_dev directory. // the migrations_dev directory.
LatestDevMigrationVersion = 1 LatestDevMigrationVersion = 0
) )
// HasDevMigrations reports whether any dev SQL migration files are embedded in
// the current build. This lets dev builds omit the separate dev migration set
// cleanly when the directory exists but currently contains no migration files.
func HasDevMigrations() bool {
files, err := fs.Glob(SqlSchemas, "sqlc/migrations_dev/*.*.sql")
if err != nil {
return false
}
return len(files) > 0
}
// MakeTestMigrationSets creates the migration sets for the unit test // MakeTestMigrationSets creates the migration sets for the unit test
// environment. // environment.
// //
@ -57,6 +71,12 @@ func MakeTestMigrationSets() []sqldb.MigrationSet {
}, },
} }
// If there are no dev migrations in the sqlc/migrations_dev folder, we
// can return early.
if !HasDevMigrations() {
return []sqldb.MigrationSet{migSet}
}
migSetDev := sqldb.MigrationSet{ migSetDev := sqldb.MigrationSet{
TrackingTableName: pgx.DefaultMigrationsTable + "_dev", TrackingTableName: pgx.DefaultMigrationsTable + "_dev",
SQLFileDirectory: "sqlc/migrations_dev", SQLFileDirectory: "sqlc/migrations_dev",

View file

@ -13,12 +13,6 @@ import (
"github.com/lightningnetwork/lnd/sqldb/v2" "github.com/lightningnetwork/lnd/sqldb/v2"
) )
const (
// DevKVDBtoSQLMigVersion is the dev version of the migration that
// migrates the kvdb to the sql database.
DevKVDBtoSQLMigVersion = 1
)
// MakeMigrationSets creates the migration sets for the dev environments. // MakeMigrationSets creates the migration sets for the dev environments.
func MakeMigrationSets(ctx context.Context, func MakeMigrationSets(ctx context.Context,
basicClient lnrpc.LightningClient, macPath string, basicClient lnrpc.LightningClient, macPath string,
@ -56,6 +50,12 @@ func MakeMigrationSets(ctx context.Context,
}, },
} }
// If there are no dev migrations in the sqlc/migrations_dev folder, we
// can return early.
if !db.HasDevMigrations() {
return []sqldb.MigrationSet{migSet}
}
// Create the dev migration set. // Create the dev migration set.
migSetDev := sqldb.MigrationSet{ migSetDev := sqldb.MigrationSet{
TrackingTableName: pgx.DefaultMigrationsTable + "_dev", TrackingTableName: pgx.DefaultMigrationsTable + "_dev",
@ -69,22 +69,10 @@ func MakeMigrationSets(ctx context.Context,
// NOTE: This MUST be updated when a new dev migration is added. // NOTE: This MUST be updated when a new dev migration is added.
LatestMigrationVersion: db.LatestDevMigrationVersion, LatestMigrationVersion: db.LatestDevMigrationVersion,
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) ( MakeProgrammaticMigrations: func(_ *sqldb.BaseDB) (
map[uint]migrate.ProgrammaticMigrEntry, error) { map[uint]migrate.ProgrammaticMigrEntry, error) {
// Any programmatic migrations added to this map will be return make(map[uint]migrate.ProgrammaticMigrEntry), nil
// executed when the dev migration number for the uint
// key is applied. If no entry exists for a
// given uint, then no programmatic migration will be
// executed for that migration number.
res := make(map[uint]migrate.ProgrammaticMigrEntry)
res[DevKVDBtoSQLMigVersion] = Mig6ProgrammaticMigration(
ctx, basicClient, baseDB, macPath, clock,
DevKVDBtoSQLMigVersion,
)
return res, nil
}, },
} }

View file

@ -1 +0,0 @@
-- Comment to ensure the file created and picked up in the migration stream.

View file

@ -1 +0,0 @@
-- Comment to ensure the file created and picked up in the migration stream.

View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
set -e set -e
shopt -s nullglob
# restore_files is a function to restore original schema files. # restore_files is a function to restore original schema files.
restore_files() { restore_files() {