mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-17 13:07:41 +02:00
The kvdb accounts db is specifically set to be created in the same folder as the macaroon path, while the sessions and rules db are created in the network folder. That means that users which have set a custom macaroon path, can have an accounts db in a separate folder than the sessions and rules db. In order to ensure that the migration from kvdb to SQL uses the correct db folders, we need to make sure that the migration code uses the same logic as the creation of the db logic.
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
//go:build !dev
|
|
|
|
package migsets
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
|
|
"github.com/golang-migrate/migrate/v4"
|
|
"github.com/golang-migrate/migrate/v4/database/pgx/v5"
|
|
"github.com/lightninglabs/lightning-terminal/db"
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
"github.com/lightningnetwork/lnd/sqldb/v2"
|
|
)
|
|
|
|
// MakeMigrationSets creates the migration sets for production environments.
|
|
func MakeMigrationSets(ctx context.Context, basicClient lnrpc.LightningClient,
|
|
macPath, litDir, network string,
|
|
clock clock.Clock) []sqldb.MigrationSet {
|
|
|
|
accountsDir := filepath.Dir(macPath)
|
|
networkDir := filepath.Join(litDir, network)
|
|
|
|
// migSet defines the SQL migration set used to create and upgrade LiT's
|
|
// SQL schema.
|
|
migSet := sqldb.MigrationSet{
|
|
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,
|
|
|
|
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) (
|
|
map[uint]migrate.ProgrammaticMigrEntry, error) {
|
|
|
|
// 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, accountsDir,
|
|
networkDir, clock, db.KVDBtoSQLMigVersion,
|
|
)
|
|
|
|
return res, nil
|
|
},
|
|
}
|
|
|
|
return []sqldb.MigrationSet{migSet}
|
|
}
|