mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
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:
parent
85d0739019
commit
10949c7bb8
5 changed files with 30 additions and 23 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/pgx/v5"
|
||||
"github.com/lightningnetwork/lnd/sqldb/v2"
|
||||
|
|
@ -28,9 +30,21 @@ const (
|
|||
//
|
||||
// NOTE: This MUST be updated when a migration is added or removed, from
|
||||
// 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
|
||||
// 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{
|
||||
TrackingTableName: pgx.DefaultMigrationsTable + "_dev",
|
||||
SQLFileDirectory: "sqlc/migrations_dev",
|
||||
|
|
|
|||
|
|
@ -13,12 +13,6 @@ import (
|
|||
"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.
|
||||
func MakeMigrationSets(ctx context.Context,
|
||||
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.
|
||||
migSetDev := sqldb.MigrationSet{
|
||||
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.
|
||||
LatestMigrationVersion: db.LatestDevMigrationVersion,
|
||||
|
||||
MakeProgrammaticMigrations: func(baseDB *sqldb.BaseDB) (
|
||||
MakeProgrammaticMigrations: func(_ *sqldb.BaseDB) (
|
||||
map[uint]migrate.ProgrammaticMigrEntry, error) {
|
||||
|
||||
// Any programmatic migrations added to this map will be
|
||||
// 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
|
||||
return make(map[uint]migrate.ProgrammaticMigrEntry), nil
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
-- Comment to ensure the file created and picked up in the migration stream.
|
||||
|
|
@ -1 +0,0 @@
|
|||
-- Comment to ensure the file created and picked up in the migration stream.
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
shopt -s nullglob
|
||||
|
||||
# restore_files is a function to restore original schema files.
|
||||
restore_files() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue