payments/db: split migration queries into dedicated SQLMigrationQueries interface
This commit is contained in:
5 files changed
+30
-18
No files matched your search
@@ -67,8 +67,14 @@ func TestMigrationWithExternalDB(t *testing.T) {
|
||||
// Run migration in a transaction.
|
||||
err := sqlStore.db.ExecTx(
|
||||
ctx, sqldb.WriteTxOpt(), func(tx SQLQueries) error {
|
||||
migTx, ok := tx.(SQLMigrationQueries)
|
||||
if !ok {
|
||||
return fmt.Errorf("db does not " +
|
||||
"implement SQLMigrationQueries")
|
||||
}
|
||||
|
||||
return MigratePaymentsKVToSQL(
|
||||
ctx, kvBackend, tx, &SQLStoreConfig{
|
||||
ctx, kvBackend, migTx, &SQLStoreConfig{
|
||||
QueryCfg: sqlStore.cfg.QueryCfg,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ type migratedPaymentRef struct {
|
||||
// with their SQL counterparts. If a structural mismatch is detected, a full
|
||||
// deep comparison is performed to produce a detailed diff for debugging.
|
||||
func validateMigratedPaymentBatch(ctx context.Context,
|
||||
kvBackend kvdb.Backend, sqlDB SQLQueries,
|
||||
kvBackend kvdb.Backend, sqlDB SQLMigrationQueries,
|
||||
cfg *SQLStoreConfig, batch []migratedPaymentRef) error {
|
||||
|
||||
if len(batch) == 0 {
|
||||
|
||||
@@ -37,7 +37,7 @@ type MigrationStats struct {
|
||||
// migrated data in batches. Callers are responsible for executing this within
|
||||
// a single SQL transaction if atomicity is required.
|
||||
func MigratePaymentsKVToSQL(ctx context.Context, kvBackend kvdb.Backend,
|
||||
sqlDB SQLQueries, cfg *SQLStoreConfig) error {
|
||||
sqlDB SQLMigrationQueries, cfg *SQLStoreConfig) error {
|
||||
|
||||
if cfg == nil {
|
||||
return fmt.Errorf("missing SQL store config for migration")
|
||||
@@ -272,7 +272,7 @@ func normalizeTimeForSQL(t time.Time) time.Time {
|
||||
|
||||
// migratePayment migrates a single payment from KV to SQL.
|
||||
func migratePayment(ctx context.Context, payment *MPPayment, hash lntypes.Hash,
|
||||
sqlDB SQLQueries, stats *MigrationStats) (int64, error) {
|
||||
sqlDB SQLMigrationQueries, stats *MigrationStats) (int64, error) {
|
||||
|
||||
// Update migration stats based on payment status.
|
||||
switch payment.Status {
|
||||
@@ -602,7 +602,7 @@ func migrateRouteHop(ctx context.Context,
|
||||
// migrateDuplicatePayments migrates duplicate payments into the dedicated
|
||||
// payment_duplicates table.
|
||||
func migrateDuplicatePayments(ctx context.Context, dupBucket kvdb.RBucket,
|
||||
hash [32]byte, primaryPaymentID int64, sqlDB SQLQueries,
|
||||
hash [32]byte, primaryPaymentID int64, sqlDB SQLMigrationQueries,
|
||||
stats *MigrationStats) error {
|
||||
|
||||
duplicateCount := 0
|
||||
@@ -660,7 +660,7 @@ func migrateDuplicatePayments(ctx context.Context, dupBucket kvdb.RBucket,
|
||||
// given payment hash into payment_duplicates.
|
||||
func migrateSingleDuplicatePayment(ctx context.Context, dupBucket kvdb.RBucket,
|
||||
hash [32]byte, primaryPaymentID int64, duplicateSeq uint64,
|
||||
sqlDB SQLQueries) error {
|
||||
sqlDB SQLMigrationQueries) error {
|
||||
|
||||
creationData := dupBucket.Get(duplicatePaymentCreationInfoKey)
|
||||
if creationData == nil {
|
||||
|
||||
@@ -88,13 +88,16 @@ type SQLQueries interface {
|
||||
// DeleteFailedAttempts removes all failed HTLCs from the db for a
|
||||
// given payment.
|
||||
DeleteFailedAttempts(ctx context.Context, paymentID int64) error
|
||||
}
|
||||
|
||||
/*
|
||||
Migration specific queries.
|
||||
|
||||
These queries are used ONLY for the one-time migration from KV
|
||||
to SQL.
|
||||
*/
|
||||
// SQLMigrationQueries extends SQLQueries with the additional queries needed
|
||||
// for the one-time migration from KV to SQL. Keeping them in a separate
|
||||
// interface makes it clear which code paths are migration-only and prevents
|
||||
// the regular store from accidentally depending on them.
|
||||
//
|
||||
//nolint:ll
|
||||
type SQLMigrationQueries interface {
|
||||
SQLQueries
|
||||
|
||||
// FetchPaymentsByIDsMig is a migration-only batch fetch that returns
|
||||
// payment data along with HTLC attempt counts for structural
|
||||
|
||||
@@ -89,13 +89,16 @@ type SQLQueries interface {
|
||||
// DeleteFailedAttempts removes all failed HTLCs from the db for a
|
||||
// given payment.
|
||||
DeleteFailedAttempts(ctx context.Context, paymentID int64) error
|
||||
}
|
||||
|
||||
/*
|
||||
Migration specific queries.
|
||||
|
||||
These queries are used ONLY for the one-time migration from KV
|
||||
to SQL.
|
||||
*/
|
||||
// SQLMigrationQueries extends SQLQueries with the additional queries needed
|
||||
// for the one-time migration from KV to SQL. Keeping them in a separate
|
||||
// interface makes it clear which code paths are migration-only and prevents
|
||||
// the regular store from accidentally depending on them.
|
||||
//
|
||||
//nolint:ll
|
||||
type SQLMigrationQueries interface {
|
||||
SQLQueries
|
||||
|
||||
// FetchPaymentsByIDsMig is a migration-only batch fetch that returns
|
||||
// payment data along with HTLC attempt counts for structural
|
||||
|
||||
Reference in new issue
Block a user