mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
multi: use sqldb/v2 in accounts package
Update the accounts package to use the `sqldb/v2` package instead of the older version.
This commit is contained in:
parent
7265ae2a85
commit
b7ee351cb0
7 changed files with 160 additions and 60 deletions
|
|
@ -8,9 +8,11 @@ import (
|
|||
|
||||
"github.com/lightninglabs/lightning-terminal/accounts"
|
||||
"github.com/lightninglabs/lightning-terminal/db"
|
||||
"github.com/lightninglabs/lightning-terminal/db/sqlc"
|
||||
"github.com/lightninglabs/lightning-terminal/firewalldb"
|
||||
"github.com/lightninglabs/lightning-terminal/session"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/sqldb/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -101,14 +103,41 @@ func NewStores(cfg *Config, clock clock.Clock) (*stores, error) {
|
|||
return stores, err
|
||||
}
|
||||
|
||||
sqlStore, err := db.NewSqliteStore(cfg.Sqlite)
|
||||
// Until we have fully added support for sqldb/v2 in all of our
|
||||
// stores, we need to use the db packages definition of the
|
||||
// SQLite store for the packages that still haven't added
|
||||
// support for sqldb/v2. This is only temporary and will be
|
||||
// removed once all stores have been updated to use sqldb/v2.
|
||||
legacySqlStore, err := db.NewSqliteStore(cfg.Sqlite)
|
||||
|
||||
sqlStore, err := sqldb.NewSqliteStore(&sqldb.SqliteConfig{
|
||||
SkipMigrations: cfg.Sqlite.SkipMigrations,
|
||||
SkipMigrationDbBackup: cfg.Sqlite.SkipMigrationDbBackup,
|
||||
}, cfg.Sqlite.DatabaseFileName)
|
||||
if err != nil {
|
||||
return stores, err
|
||||
}
|
||||
|
||||
acctStore := accounts.NewSQLStore(sqlStore.BaseDB, clock)
|
||||
sessStore := session.NewSQLStore(sqlStore.BaseDB, clock)
|
||||
firewallStore := firewalldb.NewSQLDB(sqlStore.BaseDB, clock)
|
||||
if !cfg.Sqlite.SkipMigrations {
|
||||
err = sqldb.ApplyAllMigrations(
|
||||
sqlStore, db.LitdMigrationStreams,
|
||||
)
|
||||
if err != nil {
|
||||
return stores, fmt.Errorf("error applying "+
|
||||
"migrations to SQLite store: %w", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
queries := sqlc.NewForType(sqlStore, sqlStore.BackendType)
|
||||
|
||||
acctStore := accounts.NewSQLStore(
|
||||
sqlStore.BaseDB, queries, clock,
|
||||
)
|
||||
sessStore := session.NewSQLStore(legacySqlStore.BaseDB, clock)
|
||||
firewallStore := firewalldb.NewSQLDB(
|
||||
legacySqlStore.BaseDB, clock,
|
||||
)
|
||||
|
||||
stores.accounts = acctStore
|
||||
stores.sessions = sessStore
|
||||
|
|
@ -116,14 +145,46 @@ func NewStores(cfg *Config, clock clock.Clock) (*stores, error) {
|
|||
stores.closeFns["sqlite"] = sqlStore.BaseDB.Close
|
||||
|
||||
case DatabaseBackendPostgres:
|
||||
sqlStore, err := db.NewPostgresStore(cfg.Postgres)
|
||||
// Until we have fully added support for sqldb/v2 in all of our
|
||||
// stores, we need to use the db packages definition of the
|
||||
// Postgres store for the packages that still haven't added
|
||||
// support for sqldb/v2. This is only temporary and will be
|
||||
// removed once all stores have been updated to use sqldb/v2.
|
||||
legacySqlStore, err := db.NewPostgresStore(cfg.Postgres)
|
||||
|
||||
sqlStore, err := sqldb.NewPostgresStore(&sqldb.PostgresConfig{
|
||||
Dsn: cfg.Postgres.DSN(false),
|
||||
MaxOpenConnections: cfg.Postgres.MaxOpenConnections,
|
||||
MaxIdleConnections: cfg.Postgres.MaxIdleConnections,
|
||||
ConnMaxLifetime: cfg.Postgres.ConnMaxLifetime,
|
||||
ConnMaxIdleTime: cfg.Postgres.ConnMaxIdleTime,
|
||||
RequireSSL: cfg.Postgres.RequireSSL,
|
||||
SkipMigrations: cfg.Postgres.SkipMigrations,
|
||||
})
|
||||
if err != nil {
|
||||
return stores, err
|
||||
}
|
||||
|
||||
acctStore := accounts.NewSQLStore(sqlStore.BaseDB, clock)
|
||||
sessStore := session.NewSQLStore(sqlStore.BaseDB, clock)
|
||||
firewallStore := firewalldb.NewSQLDB(sqlStore.BaseDB, clock)
|
||||
if !cfg.Postgres.SkipMigrations {
|
||||
err = sqldb.ApplyAllMigrations(
|
||||
sqlStore, db.LitdMigrationStreams,
|
||||
)
|
||||
if err != nil {
|
||||
return stores, fmt.Errorf("error applying "+
|
||||
"migrations to Postgres store: %w", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
queries := sqlc.NewForType(sqlStore, sqlStore.BackendType)
|
||||
|
||||
acctStore := accounts.NewSQLStore(
|
||||
sqlStore.BaseDB, queries, clock,
|
||||
)
|
||||
sessStore := session.NewSQLStore(legacySqlStore.BaseDB, clock)
|
||||
firewallStore := firewalldb.NewSQLDB(
|
||||
legacySqlStore.BaseDB, clock,
|
||||
)
|
||||
|
||||
stores.accounts = acctStore
|
||||
stores.sessions = sessStore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue