From 435a4623ad400bb5358a3b267331011f05f597b7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 27 Jul 2023 09:45:25 +0930 Subject: [PATCH] wallet: fix migration of existing invoices's id variable. Rusty can't type. Rusty can't test. Bad Rusty. Bad. Signed-off-by: Rusty Russell --- tests/test_invoices.py | 1 - wallet/db.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_invoices.py b/tests/test_invoices.py index 14e6a37e9..cd9612730 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -913,7 +913,6 @@ def test_listinvoices_index(node_factory, executor): assert only_one(l2.rpc.listinvoices(index='updated', start=i, limit=1)['invoices'])['label'] == str(70 + 1 - i) -@pytest.mark.xfail(strict=True) @unittest.skipIf(TEST_NETWORK != 'regtest', "The DB migration is network specific due to the chain var.") def test_invoices_wait_db_migration(node_factory, bitcoind): """Canned db is from v23.02.2's test_invoice_routeboost_private l2""" diff --git a/wallet/db.c b/wallet/db.c index 67ca768af..648c8d603 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -70,6 +70,9 @@ static void migrate_normalize_invstr(struct lightningd *ld, static void migrate_initialize_wait_indexes(struct lightningd *ld, struct db *db); +static void migrate_invoice_created_index_var(struct lightningd *ld, + struct db *db); + /* Do not reorder or remove elements from this array, it is used to * migrate existing databases from a previous state, based on the * string indices */ @@ -966,6 +969,7 @@ static struct migration dbmigrations[] = { {SQL("ALTER TABLE invoices ADD updated_index BIGINT DEFAULT 0"), NULL}, {SQL("CREATE INDEX invoice_update_idx ON invoices (updated_index)"), NULL}, {NULL, migrate_datastore_commando_runes}, + {NULL, migrate_invoice_created_index_var}, }; /** @@ -1672,6 +1676,18 @@ static void migrate_initialize_wait_indexes(struct lightningd *ld, tal_free(stmt); } +static void migrate_invoice_created_index_var(struct lightningd *ld, struct db *db) +{ + struct db_stmt *stmt; + + /* Prior migration had a typo! */ + stmt = db_prepare_v2(db, SQL("UPDATE vars" + " SET name = 'last_invoices_created_index'" + " WHERE name = 'last_invoice_created_index'")); + db_exec_prepared_v2(stmt); + tal_free(stmt); +} + static void complain_unfixed(struct lightningd *ld, enum channel_state state, u64 id,