db: move kvdb to SQL programmatic migration to prod

Move the programmatic KVDB-to-SQL migration out of the dev-only
migration stream and into the production SQL migration set.

This also requires that we add a new migration file for the prod
migration, which will trigger the kvdb to sql programmatic migration to
run in production.
This commit is contained in:
Viktor Torstensson 2026-05-12 12:55:19 +02:00
parent 3d8779693a
commit 85d0739019
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4
5 changed files with 48 additions and 20 deletions

View file

@ -12,7 +12,14 @@ const (
// daemon.
//
// NOTE: This MUST be updated when a new migration is added.
LatestMigrationVersion = 5
LatestMigrationVersion = 6
// KVDBtoSQLMigVersion is the version of the migration that migrates the
// kvdb to the sql database.
//
// NOTE: This version value should not be updated when a new migration
// is added, as this represents a specific migration.
KVDBtoSQLMigVersion = 6
// LatestDevMigrationVersion is the latest dev migration version of the
// database. This is used to implement downgrade protection for the

View file

@ -1,5 +1,3 @@
//go:build dev
package migsets
import (

View file

@ -14,8 +14,8 @@ import (
)
// MakeMigrationSets creates the migration sets for production environments.
func MakeMigrationSets(_ context.Context, _ lnrpc.LightningClient, _ string,
_ clock.Clock) []sqldb.MigrationSet {
func MakeMigrationSets(ctx context.Context, basicClient lnrpc.LightningClient,
macPath string, clock clock.Clock) []sqldb.MigrationSet {
// migSet defines the SQL migration set used to create and upgrade LiT's
// SQL schema.
@ -31,10 +31,22 @@ func MakeMigrationSets(_ context.Context, _ lnrpc.LightningClient, _ string,
// NOTE: This MUST be updated when a new migration is added.
LatestMigrationVersion: db.LatestMigrationVersion,
MakeProgrammaticMigrations: func(db *sqldb.BaseDB) (
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) (
map[uint]migrate.ProgrammaticMigrEntry, error) {
return make(map[uint]migrate.ProgrammaticMigrEntry), nil
// Any programmatic migrations added to this map will be
// executed when the 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[db.KVDBtoSQLMigVersion] = Mig6ProgrammaticMigration(
ctx, basicClient, baseDB, macPath, clock,
db.KVDBtoSQLMigVersion,
)
return res, nil
},
}

View file

@ -14,13 +14,9 @@ import (
)
const (
// KVDBtoSQLMigVersion is the version of the migration that migrates the
// kvdb to the sql database.
//
// TODO: When this the kvdb to sql migration goes live into prod, this
// should be moved to non dev db/migrations.go file, and this constant
// value should be updated to reflect the real migration number.
KVDBtoSQLMigVersion = 1
// 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.
@ -41,10 +37,22 @@ func MakeMigrationSets(ctx context.Context,
// NOTE: This MUST be updated when a new migration is added.
LatestMigrationVersion: db.LatestMigrationVersion,
MakeProgrammaticMigrations: func(db *sqldb.BaseDB) (
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) (
map[uint]migrate.ProgrammaticMigrEntry, error) {
return make(map[uint]migrate.ProgrammaticMigrEntry), nil
// Any programmatic migrations added to this map will be
// executed when the 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[db.KVDBtoSQLMigVersion] = Mig6ProgrammaticMigration(
ctx, basicClient, baseDB, macPath, clock,
db.KVDBtoSQLMigVersion,
)
return res, nil
},
}
@ -61,7 +69,7 @@ func MakeMigrationSets(ctx context.Context,
// NOTE: This MUST be updated when a new dev migration is added.
LatestMigrationVersion: db.LatestDevMigrationVersion,
MakeProgrammaticMigrations: func(db *sqldb.BaseDB) (
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) (
map[uint]migrate.ProgrammaticMigrEntry, error) {
// Any programmatic migrations added to this map will be
@ -71,9 +79,9 @@ func MakeMigrationSets(ctx context.Context,
// executed for that migration number.
res := make(map[uint]migrate.ProgrammaticMigrEntry)
res[KVDBtoSQLMigVersion] = Mig6ProgrammaticMigration(
ctx, basicClient, db, macPath, clock,
KVDBtoSQLMigVersion,
res[DevKVDBtoSQLMigVersion] = Mig6ProgrammaticMigration(
ctx, basicClient, baseDB, macPath, clock,
DevKVDBtoSQLMigVersion,
)
return res, nil

View file

@ -0,0 +1,3 @@
-- Comment to ensure the file created and picked up in the migration stream.
-- NOTE: There's intentionally no corresponding .down file for this migration
-- to ensure that the KVDB -> SQL migration isn't executed on db downgrades.