sqldb+payments: add payment_duplicates for legacy duplicate payments
Older LND versions could create multiple payments for the same hash. We need to preserve those historical records during KV→SQL migration, but they don’t fit the normal payment schema because we enforce a unique payment hash constraint. Introduce a lean payment_duplicates table to store only the essential fields (identifier, amount, timestamps, settle/fail data). This keeps the primary payment records stable and makes the migration deterministic even when duplicate records lack attempt info. The table is intentionally minimal and can be dropped after migration if no duplicate payments exist. For now there is no logic in place which allows the noderunner to fetch duplicate payments after the migration.
This commit is contained in:
7 files changed
+195
-1
No files matched your search
@@ -40,6 +40,21 @@ FROM payments p
|
||||
LEFT JOIN payment_intents i ON i.payment_id = p.id
|
||||
WHERE p.payment_identifier = $1;
|
||||
|
||||
-- name: FetchPaymentDuplicates :many
|
||||
-- Fetch all duplicate payment records from the payment_duplicates table for
|
||||
-- a given payment ID.
|
||||
SELECT
|
||||
id,
|
||||
payment_id,
|
||||
amount_msat,
|
||||
created_at,
|
||||
fail_reason,
|
||||
settle_preimage,
|
||||
settle_time
|
||||
FROM payment_duplicates
|
||||
WHERE payment_id = $1
|
||||
ORDER BY id ASC;
|
||||
|
||||
-- name: CountPayments :one
|
||||
SELECT COUNT(*) FROM payments;
|
||||
|
||||
@@ -408,4 +423,25 @@ FROM payments p
|
||||
LEFT JOIN payment_htlc_attempts ha ON ha.payment_id = p.id
|
||||
WHERE p.id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/)
|
||||
GROUP BY p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason
|
||||
ORDER BY p.id ASC;
|
||||
ORDER BY p.id ASC;
|
||||
|
||||
-- name: InsertPaymentDuplicateMig :one
|
||||
-- Insert a duplicate payment record into the payment_duplicates table and
|
||||
-- return its ID.
|
||||
INSERT INTO payment_duplicates (
|
||||
payment_id,
|
||||
amount_msat,
|
||||
created_at,
|
||||
fail_reason,
|
||||
settle_preimage,
|
||||
settle_time
|
||||
)
|
||||
VALUES (
|
||||
@payment_id,
|
||||
@amount_msat,
|
||||
@created_at,
|
||||
@fail_reason,
|
||||
@settle_preimage,
|
||||
@settle_time
|
||||
)
|
||||
RETURNING id;
|
||||
Reference in new issue
Block a user