Skip to content

Commit

Permalink
wallet: fix migration of existing invoices's id variable.
Browse files Browse the repository at this point in the history
Rusty can't type.  Rusty can't test.  Bad Rusty.  Bad.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jul 27, 2023
1 parent 8f3b80d commit e695cc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion tests/test_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
16 changes: 16 additions & 0 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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},
};

/**
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e695cc6

Please sign in to comment.