diff --git a/payments/db/migration1/migration_external_test.go b/payments/db/migration1/migration_external_test.go index a5ddc42c8..85f828961 100644 --- a/payments/db/migration1/migration_external_test.go +++ b/payments/db/migration1/migration_external_test.go @@ -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, }, ) diff --git a/payments/db/migration1/migration_validation.go b/payments/db/migration1/migration_validation.go index e6f8bdd48..b2192e944 100644 --- a/payments/db/migration1/migration_validation.go +++ b/payments/db/migration1/migration_validation.go @@ -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 { diff --git a/payments/db/migration1/sql_migration.go b/payments/db/migration1/sql_migration.go index 626b25a61..b20811760 100644 --- a/payments/db/migration1/sql_migration.go +++ b/payments/db/migration1/sql_migration.go @@ -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 { diff --git a/payments/db/migration1/sql_store.go b/payments/db/migration1/sql_store.go index 0fe4aa1fc..2a2c97752 100644 --- a/payments/db/migration1/sql_store.go +++ b/payments/db/migration1/sql_store.go @@ -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 diff --git a/payments/db/sql_store.go b/payments/db/sql_store.go index 2c8dde93d..1c8ffb581 100644 --- a/payments/db/sql_store.go +++ b/payments/db/sql_store.go @@ -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