Skip to content

Commit dc5ff92

Browse files
firewalldb: use sqlcmig6 for kvdb to sql migration
1 parent ec2ade5 commit dc5ff92

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

firewalldb/sql_migration.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"errors"
88
"fmt"
99

10-
"github.com/lightninglabs/lightning-terminal/db/sqlc"
10+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
1111
"github.com/lightningnetwork/lnd/fn"
1212
"github.com/lightningnetwork/lnd/sqldb"
1313
"go.etcd.io/bbolt"
@@ -78,7 +78,7 @@ func (e *kvEntry) namespacedKey() string {
7878
// NOTE: As sessions may contain linked sessions and accounts, the sessions and
7979
// accounts sql migration MUST be run prior to this migration.
8080
func MigrateFirewallDBToSQL(ctx context.Context, kvStore *bbolt.DB,
81-
sqlTx SQLQueries) error {
81+
sqlTx SQLMig6Queries) error {
8282

8383
log.Infof("Starting migration of the rules DB to SQL")
8484

@@ -99,7 +99,7 @@ func MigrateFirewallDBToSQL(ctx context.Context, kvStore *bbolt.DB,
9999
// database to the SQL database. The function also asserts that the
100100
// migrated values match the original values in the KV store.
101101
func migrateKVStoresDBToSQL(ctx context.Context, kvStore *bbolt.DB,
102-
sqlTx SQLQueries) error {
102+
sqlTx SQLMig6Queries) error {
103103

104104
log.Infof("Starting migration of the KV stores to SQL")
105105

@@ -361,15 +361,15 @@ func collectKVPairs(bkt *bbolt.Bucket, errorOnBuckets, perm bool,
361361
}
362362

363363
// insertPair inserts a single key-value pair into the SQL database.
364-
func insertPair(ctx context.Context, tx SQLQueries,
364+
func insertPair(ctx context.Context, tx SQLMig6Queries,
365365
entry *kvEntry) (*sqlKvEntry, error) {
366366

367367
ruleID, err := tx.GetOrInsertRuleID(ctx, entry.ruleName)
368368
if err != nil {
369369
return nil, err
370370
}
371371

372-
p := sqlc.InsertKVStoreRecordParams{
372+
p := sqlcmig6.InsertKVStoreRecordParams{
373373
Perm: entry.perm,
374374
RuleID: ruleID,
375375
EntryKey: entry.key,
@@ -421,13 +421,13 @@ func insertPair(ctx context.Context, tx SQLQueries,
421421

422422
// getSQLValue retrieves the key value for the given kvEntry from the SQL
423423
// database.
424-
func getSQLValue(ctx context.Context, tx SQLQueries,
424+
func getSQLValue(ctx context.Context, tx SQLMig6Queries,
425425
entry *sqlKvEntry) ([]byte, error) {
426426

427427
switch {
428428
case entry.featureID.Valid && entry.groupID.Valid:
429429
return tx.GetFeatureKVStoreRecord(
430-
ctx, sqlc.GetFeatureKVStoreRecordParams{
430+
ctx, sqlcmig6.GetFeatureKVStoreRecordParams{
431431
Perm: entry.perm,
432432
RuleID: entry.ruleID,
433433
GroupID: entry.groupID,
@@ -437,7 +437,7 @@ func getSQLValue(ctx context.Context, tx SQLQueries,
437437
)
438438
case entry.groupID.Valid:
439439
return tx.GetGroupKVStoreRecord(
440-
ctx, sqlc.GetGroupKVStoreRecordParams{
440+
ctx, sqlcmig6.GetGroupKVStoreRecordParams{
441441
Perm: entry.perm,
442442
RuleID: entry.ruleID,
443443
GroupID: entry.groupID,
@@ -446,7 +446,7 @@ func getSQLValue(ctx context.Context, tx SQLQueries,
446446
)
447447
case !entry.featureID.Valid && !entry.groupID.Valid:
448448
return tx.GetGlobalKVStoreRecord(
449-
ctx, sqlc.GetGlobalKVStoreRecordParams{
449+
ctx, sqlcmig6.GetGlobalKVStoreRecordParams{
450450
Perm: entry.perm,
451451
RuleID: entry.ruleID,
452452
Key: entry.key,

firewalldb/sql_migration_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/lightninglabs/lightning-terminal/accounts"
12-
"github.com/lightninglabs/lightning-terminal/db/sqlc"
12+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
1313
"github.com/lightninglabs/lightning-terminal/session"
1414
"github.com/lightningnetwork/lnd/clock"
1515
"github.com/lightningnetwork/lnd/fn"
@@ -53,24 +53,24 @@ func TestFirewallDBMigration(t *testing.T) {
5353
}
5454

5555
makeSQLDB := func(t *testing.T,
56-
sessionsStore session.Store) *SQLQueriesExecutor[SQLQueries] {
56+
sStore session.Store) *SQLMig6QueriesExecutor[SQLMig6Queries] {
5757

58-
testDBStore := NewTestDBWithSessions(t, sessionsStore, clock)
58+
testDBStore := NewTestDBWithSessions(t, sStore, clock)
5959

6060
store, ok := testDBStore.(*SQLDB)
6161
require.True(t, ok)
6262

6363
baseDB := store.BaseDB
6464

65-
queries := sqlc.NewForType(baseDB, baseDB.BackendType)
65+
queries := sqlcmig6.NewForType(baseDB, baseDB.BackendType)
6666

67-
return NewSQLQueriesExecutor(baseDB, queries)
67+
return NewSQLMig6QueriesExecutor(baseDB, queries)
6868
}
6969

7070
// The assertMigrationResults function will currently assert that
7171
// the migrated kv stores entries in the SQLDB match the original kv
7272
// stores entries in the BoltDB.
73-
assertMigrationResults := func(t *testing.T, store SQLQueries,
73+
assertMigrationResults := func(t *testing.T, store SQLMig6Queries,
7474
kvEntries []*kvEntry) {
7575

7676
var (
@@ -141,7 +141,7 @@ func TestFirewallDBMigration(t *testing.T) {
141141
if entry.groupAlias.IsNone() {
142142
sqlVal, err := store.GetGlobalKVStoreRecord(
143143
ctx,
144-
sqlc.GetGlobalKVStoreRecordParams{
144+
sqlcmig6.GetGlobalKVStoreRecordParams{
145145
Key: entry.key,
146146
Perm: entry.perm,
147147
RuleID: ruleID,
@@ -159,7 +159,7 @@ func TestFirewallDBMigration(t *testing.T) {
159159

160160
v, err := store.GetGroupKVStoreRecord(
161161
ctx,
162-
sqlc.GetGroupKVStoreRecordParams{
162+
sqlcmig6.GetGroupKVStoreRecordParams{
163163
Key: entry.key,
164164
Perm: entry.perm,
165165
RuleID: ruleID,
@@ -184,7 +184,7 @@ func TestFirewallDBMigration(t *testing.T) {
184184

185185
sqlVal, err := store.GetFeatureKVStoreRecord(
186186
ctx,
187-
sqlc.GetFeatureKVStoreRecordParams{
187+
sqlcmig6.GetFeatureKVStoreRecordParams{
188188
Key: entry.key,
189189
Perm: entry.perm,
190190
RuleID: ruleID,
@@ -296,7 +296,7 @@ func TestFirewallDBMigration(t *testing.T) {
296296
// sqldb v2 is based on the latest version of lnd/sqldb.
297297
var opts sqldb.MigrationTxOptions
298298
err = txEx.ExecTx(ctx, &opts,
299-
func(tx SQLQueries) error {
299+
func(tx SQLMig6Queries) error {
300300
err = MigrateFirewallDBToSQL(
301301
ctx, firewallStore.DB, tx,
302302
)

0 commit comments

Comments
 (0)