mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
migstreams: introduce migstreams package
The upcoming kvdb to sql code migration will be added to as part of the `sqldb/v2` migration stream. However, since the kvdb to sql migration will need to use the migration functions present in the `accounts`, `firewalldb`, and `session` packages, the migration will need to referernce those packages. That would lead to a circular dependency though if the migration stream was defined in the `db` package, as those packages need to import the `db` package. To avoid this, we introduce a new `migstreams` package that contains the migration streams, and ensure that the `db` package doesn't import the `migstreams` package.
This commit is contained in:
parent
08b91b09ef
commit
0d96fd8dad
5 changed files with 40 additions and 5 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/lightninglabs/lightning-terminal/accounts"
|
||||
"github.com/lightninglabs/lightning-terminal/db"
|
||||
"github.com/lightninglabs/lightning-terminal/db/migstreams"
|
||||
"github.com/lightninglabs/lightning-terminal/db/sqlc"
|
||||
"github.com/lightninglabs/lightning-terminal/firewalldb"
|
||||
"github.com/lightninglabs/lightning-terminal/session"
|
||||
|
|
@ -113,7 +114,7 @@ func NewStores(cfg *Config, clock clock.Clock) (*stores, error) {
|
|||
|
||||
if !cfg.Sqlite.SkipMigrations {
|
||||
err = sqldb.ApplyAllMigrations(
|
||||
sqlStore, db.LitdMigrationStreams,
|
||||
sqlStore, migstreams.LitdMigrationStreams,
|
||||
)
|
||||
if err != nil {
|
||||
return stores, fmt.Errorf("error applying "+
|
||||
|
|
@ -155,7 +156,7 @@ func NewStores(cfg *Config, clock clock.Clock) (*stores, error) {
|
|||
|
||||
if !cfg.Postgres.SkipMigrations {
|
||||
err = sqldb.ApplyAllMigrations(
|
||||
sqlStore, db.LitdMigrationStreams,
|
||||
sqlStore, migstreams.LitdMigrationStreams,
|
||||
)
|
||||
if err != nil {
|
||||
return stores, fmt.Errorf("error applying "+
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ const (
|
|||
|
||||
// MakeTestMigrationStreams creates the migration streams for the unit test
|
||||
// environment.
|
||||
//
|
||||
// NOTE: This function is not located in the migstreams package to avoid
|
||||
// cyclic dependencies.
|
||||
func MakeTestMigrationStreams() []sqldb.MigrationStream {
|
||||
migStream := sqldb.MigrationStream{
|
||||
TrackingTableName: pgx.DefaultMigrationsTable,
|
||||
|
|
|
|||
25
db/migstreams/log.go
Normal file
25
db/migstreams/log.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package migstreams
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btclog/v2"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
const Subsystem = "MIGS"
|
||||
|
||||
// log is a logger that is initialized with no output filters. This
|
||||
// means the package will not perform any logging by default until the caller
|
||||
// requests it.
|
||||
var log btclog.Logger
|
||||
|
||||
// The default amount of logging is none.
|
||||
func init() {
|
||||
UseLogger(build.NewSubLogger(Subsystem, nil))
|
||||
}
|
||||
|
||||
// UseLogger uses a specified Logger to output package logging info.
|
||||
// This should be used in preference to SetLogWriter if the caller is also
|
||||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package db
|
||||
package migstreams
|
||||
|
||||
import (
|
||||
"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/sqldb/v2"
|
||||
)
|
||||
|
||||
|
|
@ -12,14 +13,14 @@ var (
|
|||
LitdMigrationStream = sqldb.MigrationStream{
|
||||
TrackingTableName: pgx.DefaultMigrationsTable,
|
||||
SQLFileDirectory: "sqlc/migrations",
|
||||
SQLFiles: SqlSchemas,
|
||||
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: LatestMigrationVersion,
|
||||
LatestMigrationVersion: db.LatestMigrationVersion,
|
||||
|
||||
MakeProgrammaticMigrations: func(db *sqldb.BaseDB) (
|
||||
map[uint]migrate.ProgrammaticMigrEntry, error) {
|
||||
5
log.go
5
log.go
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/lightninglabs/lightning-terminal/accounts"
|
||||
"github.com/lightninglabs/lightning-terminal/autopilotserver"
|
||||
"github.com/lightninglabs/lightning-terminal/db"
|
||||
"github.com/lightninglabs/lightning-terminal/db/migstreams"
|
||||
"github.com/lightninglabs/lightning-terminal/firewall"
|
||||
"github.com/lightninglabs/lightning-terminal/firewalldb"
|
||||
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
|
||||
|
|
@ -93,6 +94,10 @@ func SetupLoggers(root *build.SubLoggerManager, intercept signal.Interceptor) {
|
|||
)
|
||||
lnd.AddSubLogger(root, db.Subsystem, intercept, db.UseLogger)
|
||||
lnd.AddSubLogger(root, sqldb.Subsystem, intercept, sqldb.UseLogger)
|
||||
lnd.AddSubLogger(
|
||||
root, migstreams.Subsystem, intercept,
|
||||
migstreams.UseLogger,
|
||||
)
|
||||
|
||||
// Add daemon loggers to lnd's root logger.
|
||||
faraday.SetupLoggers(root, intercept)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue