From 344579b23364208ca148e5618c4c9c7858eb5713 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 29 Oct 2021 13:20:09 +0200 Subject: [PATCH] wallet: Re-sync the payments.id sequence with postgresql Fixes #4883 Fixes #4879 Changelog-None: Unreleased bug being fixed. --- wallet/db.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wallet/db.c b/wallet/db.c index 1b6c8f02d..2b0b9740c 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -855,6 +855,9 @@ static struct migration dbmigrations[] = { /* We default to 50k sats */ {SQL("ALTER TABLE channel_configs ADD max_dust_htlc_exposure_msat BIGINT DEFAULT 50000000"), NULL}, {SQL("ALTER TABLE channel_htlcs ADD fail_immediate INTEGER DEFAULT 0"), NULL}, + + /* Issue #4887: reset the payments.id sequence after the migration above. Since this is a SELECT statement that would otherwise fail, make it an INSERT into the `vars` table.*/ + {SQL("/*PSQL*/INSERT INTO vars (name, intval) VALUES ('payment_id_reset', setval(pg_get_serial_sequence('payments', 'id'), COALESCE((SELECT MAX(id)+1 FROM payments), 1)))"), NULL}, }; /* Leak tracking. */