6
6
"database/sql"
7
7
"errors"
8
8
"fmt"
9
-
10
- "github.com/lightninglabs/lightning-terminal/db/sqlc"
9
+ "github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
11
10
"github.com/lightningnetwork/lnd/fn"
12
11
"github.com/lightningnetwork/lnd/sqldb"
13
12
"go.etcd.io/bbolt"
@@ -80,7 +79,7 @@ type privacyPairs = map[int64]map[string]string
80
79
// NOTE: As sessions may contain linked sessions and accounts, the sessions and
81
80
// accounts sql migration MUST be run prior to this migration.
82
81
func MigrateFirewallDBToSQL (ctx context.Context , kvStore * bbolt.DB ,
83
- sqlTx SQLQueries ) error {
82
+ sqlTx * sqlcmig6. Queries ) error {
84
83
85
84
log .Infof ("Starting migration of the rules DB to SQL" )
86
85
@@ -105,7 +104,7 @@ func MigrateFirewallDBToSQL(ctx context.Context, kvStore *bbolt.DB,
105
104
// database to the SQL database. The function also asserts that the
106
105
// migrated values match the original values in the KV store.
107
106
func migrateKVStoresDBToSQL (ctx context.Context , kvStore * bbolt.DB ,
108
- sqlTx SQLQueries ) error {
107
+ sqlTx * sqlcmig6. Queries ) error {
109
108
110
109
log .Infof ("Starting migration of the KV stores to SQL" )
111
110
@@ -367,15 +366,15 @@ func collectKVPairs(bkt *bbolt.Bucket, errorOnBuckets, perm bool,
367
366
}
368
367
369
368
// insertPair inserts a single key-value pair into the SQL database.
370
- func insertPair (ctx context.Context , tx SQLQueries ,
369
+ func insertPair (ctx context.Context , tx * sqlcmig6. Queries ,
371
370
entry * kvEntry ) (* sqlKvEntry , error ) {
372
371
373
372
ruleID , err := tx .GetOrInsertRuleID (ctx , entry .ruleName )
374
373
if err != nil {
375
374
return nil , err
376
375
}
377
376
378
- p := sqlc .InsertKVStoreRecordParams {
377
+ p := sqlcmig6 .InsertKVStoreRecordParams {
379
378
Perm : entry .perm ,
380
379
RuleID : ruleID ,
381
380
EntryKey : entry .key ,
@@ -427,13 +426,13 @@ func insertPair(ctx context.Context, tx SQLQueries,
427
426
428
427
// getSQLValue retrieves the key value for the given kvEntry from the SQL
429
428
// database.
430
- func getSQLValue (ctx context.Context , tx SQLQueries ,
429
+ func getSQLValue (ctx context.Context , tx * sqlcmig6. Queries ,
431
430
entry * sqlKvEntry ) ([]byte , error ) {
432
431
433
432
switch {
434
433
case entry .featureID .Valid && entry .groupID .Valid :
435
434
return tx .GetFeatureKVStoreRecord (
436
- ctx , sqlc .GetFeatureKVStoreRecordParams {
435
+ ctx , sqlcmig6 .GetFeatureKVStoreRecordParams {
437
436
Perm : entry .perm ,
438
437
RuleID : entry .ruleID ,
439
438
GroupID : entry .groupID ,
@@ -443,7 +442,7 @@ func getSQLValue(ctx context.Context, tx SQLQueries,
443
442
)
444
443
case entry .groupID .Valid :
445
444
return tx .GetGroupKVStoreRecord (
446
- ctx , sqlc .GetGroupKVStoreRecordParams {
445
+ ctx , sqlcmig6 .GetGroupKVStoreRecordParams {
447
446
Perm : entry .perm ,
448
447
RuleID : entry .ruleID ,
449
448
GroupID : entry .groupID ,
@@ -452,7 +451,7 @@ func getSQLValue(ctx context.Context, tx SQLQueries,
452
451
)
453
452
case ! entry .featureID .Valid && ! entry .groupID .Valid :
454
453
return tx .GetGlobalKVStoreRecord (
455
- ctx , sqlc .GetGlobalKVStoreRecordParams {
454
+ ctx , sqlcmig6 .GetGlobalKVStoreRecordParams {
456
455
Perm : entry .perm ,
457
456
RuleID : entry .ruleID ,
458
457
Key : entry .key ,
@@ -501,7 +500,7 @@ func verifyBktKeys(bkt *bbolt.Bucket, errorOnKeyValues bool,
501
500
// from the KV database to the SQL database. The function also asserts that the
502
501
// migrated values match the original values in the privacy mapper store.
503
502
func migratePrivacyMapperDBToSQL (ctx context.Context , kvStore * bbolt.DB ,
504
- sqlTx SQLQueries ) error {
503
+ sqlTx * sqlcmig6. Queries ) error {
505
504
506
505
log .Infof ("Starting migration of the privacy mapper store to SQL" )
507
506
@@ -536,7 +535,7 @@ func migratePrivacyMapperDBToSQL(ctx context.Context, kvStore *bbolt.DB,
536
535
537
536
// collectPrivacyPairs collects all privacy pairs from the KV store.
538
537
func collectPrivacyPairs (ctx context.Context , kvStore * bbolt.DB ,
539
- sqlTx SQLQueries ) (privacyPairs , error ) {
538
+ sqlTx * sqlcmig6. Queries ) (privacyPairs , error ) {
540
539
541
540
groupPairs := make (privacyPairs )
542
541
@@ -665,7 +664,7 @@ func collectPairs(pairsBucket *bbolt.Bucket) (map[string]string, error) {
665
664
}
666
665
667
666
// insertPrivacyPairs inserts the collected privacy pairs into the SQL database.
668
- func insertPrivacyPairs (ctx context.Context , sqlTx SQLQueries ,
667
+ func insertPrivacyPairs (ctx context.Context , sqlTx * sqlcmig6. Queries ,
669
668
pairs privacyPairs ) error {
670
669
671
670
for groupId , groupPairs := range pairs {
@@ -684,12 +683,12 @@ func insertPrivacyPairs(ctx context.Context, sqlTx SQLQueries,
684
683
// an error if a duplicate pair is found. The function takes a map of real
685
684
// to pseudo values, where the key is the real value and the value is the
686
685
// corresponding pseudo value.
687
- func insertGroupPairs (ctx context.Context , sqlTx SQLQueries , groupID int64 ,
688
- pairs map [string ]string ) error {
686
+ func insertGroupPairs (ctx context.Context , sqlTx * sqlcmig6. Queries ,
687
+ groupID int64 , pairs map [string ]string ) error {
689
688
690
689
for realVal , pseudoVal := range pairs {
691
690
err := sqlTx .InsertPrivacyPair (
692
- ctx , sqlc .InsertPrivacyPairParams {
691
+ ctx , sqlcmig6 .InsertPrivacyPairParams {
693
692
GroupID : groupID ,
694
693
RealVal : realVal ,
695
694
PseudoVal : pseudoVal ,
@@ -706,7 +705,7 @@ func insertGroupPairs(ctx context.Context, sqlTx SQLQueries, groupID int64,
706
705
707
706
// validatePrivacyPairsMigration validates that the migrated privacy pairs
708
707
// match the original values in the KV store.
709
- func validatePrivacyPairsMigration (ctx context.Context , sqlTx SQLQueries ,
708
+ func validatePrivacyPairsMigration (ctx context.Context , sqlTx * sqlcmig6. Queries ,
710
709
pairs privacyPairs ) error {
711
710
712
711
for groupId , groupPairs := range pairs {
@@ -727,12 +726,12 @@ func validatePrivacyPairsMigration(ctx context.Context, sqlTx SQLQueries,
727
726
// for each real value, the pseudo value in the SQL database matches the
728
727
// original pseudo value, and vice versa. If any mismatch is found, it returns
729
728
// an error indicating the mismatch.
730
- func validateGroupPairsMigration (ctx context.Context , sqlTx SQLQueries ,
729
+ func validateGroupPairsMigration (ctx context.Context , sqlTx * sqlcmig6. Queries ,
731
730
groupID int64 , pairs map [string ]string ) error {
732
731
733
732
for realVal , pseudoVal := range pairs {
734
733
resPseudoVal , err := sqlTx .GetPseudoForReal (
735
- ctx , sqlc .GetPseudoForRealParams {
734
+ ctx , sqlcmig6 .GetPseudoForRealParams {
736
735
GroupID : groupID ,
737
736
RealVal : realVal ,
738
737
},
@@ -752,7 +751,7 @@ func validateGroupPairsMigration(ctx context.Context, sqlTx SQLQueries,
752
751
}
753
752
754
753
resRealVal , err := sqlTx .GetRealForPseudo (
755
- ctx , sqlc .GetRealForPseudoParams {
754
+ ctx , sqlcmig6 .GetRealForPseudoParams {
756
755
GroupID : groupID ,
757
756
PseudoVal : pseudoVal ,
758
757
},
0 commit comments