2025-07-11 21:38:29 +02:00
|
|
|
//go:build dev
|
|
|
|
|
|
2026-03-26 11:59:04 +01:00
|
|
|
package migsets
|
2025-07-11 21:38:29 +02:00
|
|
|
|
|
|
|
|
import (
|
2025-07-24 02:43:17 +02:00
|
|
|
"context"
|
|
|
|
|
|
2025-07-11 21:38:29 +02:00
|
|
|
"github.com/golang-migrate/migrate/v4"
|
|
|
|
|
"github.com/golang-migrate/migrate/v4/database/pgx/v5"
|
|
|
|
|
"github.com/lightninglabs/lightning-terminal/db"
|
2025-07-24 02:43:17 +02:00
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
2025-07-11 21:38:29 +02:00
|
|
|
"github.com/lightningnetwork/lnd/sqldb/v2"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-26 11:57:14 +01:00
|
|
|
// MakeMigrationSets creates the migration sets for the dev environments.
|
|
|
|
|
func MakeMigrationSets(ctx context.Context,
|
2025-07-24 02:43:17 +02:00
|
|
|
basicClient lnrpc.LightningClient, macPath string,
|
2026-03-26 11:50:34 +01:00
|
|
|
clock clock.Clock) []sqldb.MigrationSet {
|
2025-07-24 02:43:17 +02:00
|
|
|
|
2026-03-26 11:57:14 +01:00
|
|
|
// Create the prod migration set.
|
|
|
|
|
migSet := sqldb.MigrationSet{
|
2025-07-11 21:38:29 +02:00
|
|
|
TrackingTableName: pgx.DefaultMigrationsTable,
|
|
|
|
|
SQLFileDirectory: "sqlc/migrations",
|
|
|
|
|
SQLFiles: db.SqlSchemas,
|
|
|
|
|
|
|
|
|
|
// LatestMigrationVersion is the latest migration version of the
|
|
|
|
|
// database. This is used to implement downgrade protection for
|
|
|
|
|
// the daemon.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: This MUST be updated when a new migration is added.
|
|
|
|
|
LatestMigrationVersion: db.LatestMigrationVersion,
|
|
|
|
|
|
2026-05-12 12:55:19 +02:00
|
|
|
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) (
|
2025-07-11 21:38:29 +02:00
|
|
|
map[uint]migrate.ProgrammaticMigrEntry, error) {
|
|
|
|
|
|
2026-05-12 12:55:19 +02:00
|
|
|
// 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
|
2025-07-11 21:38:29 +02:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 12:58:16 +02:00
|
|
|
// If there are no dev migrations in the sqlc/migrations_dev folder, we
|
|
|
|
|
// can return early.
|
|
|
|
|
if !db.HasDevMigrations() {
|
|
|
|
|
return []sqldb.MigrationSet{migSet}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 11:57:14 +01:00
|
|
|
// Create the dev migration set.
|
|
|
|
|
migSetDev := sqldb.MigrationSet{
|
2025-07-11 21:38:29 +02:00
|
|
|
TrackingTableName: pgx.DefaultMigrationsTable + "_dev",
|
|
|
|
|
SQLFileDirectory: "sqlc/migrations_dev",
|
|
|
|
|
SQLFiles: db.SqlSchemas,
|
|
|
|
|
|
|
|
|
|
// LatestMigrationVersion is the latest migration version of the
|
|
|
|
|
// dev migrations database. This is used to implement downgrade
|
|
|
|
|
// protection for the daemon.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: This MUST be updated when a new dev migration is added.
|
|
|
|
|
LatestMigrationVersion: db.LatestDevMigrationVersion,
|
|
|
|
|
|
2026-05-12 12:58:16 +02:00
|
|
|
MakeProgrammaticMigrations: func(_ *sqldb.BaseDB) (
|
2025-07-11 21:38:29 +02:00
|
|
|
map[uint]migrate.ProgrammaticMigrEntry, error) {
|
|
|
|
|
|
2026-05-12 12:58:16 +02:00
|
|
|
return make(map[uint]migrate.ProgrammaticMigrEntry), nil
|
2025-07-11 21:38:29 +02:00
|
|
|
},
|
|
|
|
|
}
|
2025-07-24 02:43:17 +02:00
|
|
|
|
2026-03-26 11:57:14 +01:00
|
|
|
return []sqldb.MigrationSet{migSet, migSetDev}
|
2025-07-24 02:43:17 +02:00
|
|
|
}
|