mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
db: fix migrations which write to db.
valgrind noticed that this was uninitialized when I tried a complex migration. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6438ee4126
commit
d7aa2749c3
@ -45,8 +45,11 @@ u32 db_data_version_get(struct db *db)
|
||||
u32 version;
|
||||
stmt = db_prepare_v2(db, SQL("SELECT intval FROM vars WHERE name = 'data_version'"));
|
||||
db_query_prepared(stmt);
|
||||
db_step(stmt);
|
||||
version = db_col_int(stmt, "intval");
|
||||
/* This fails on uninitialized db, so "0" */
|
||||
if (db_step(stmt))
|
||||
version = db_col_int(stmt, "intval");
|
||||
else
|
||||
version = 0;
|
||||
tal_free(stmt);
|
||||
return version;
|
||||
}
|
||||
|
@ -950,10 +950,10 @@ struct db *db_setup(const tal_t *ctx, struct lightningd *ld,
|
||||
db->report_changes_fn = plugin_hook_db_sync;
|
||||
|
||||
db_begin_transaction(db);
|
||||
db->data_version = db_data_version_get(db);
|
||||
|
||||
migrated = db_migrate(ld, db, bip32_base);
|
||||
|
||||
db->data_version = db_data_version_get(db);
|
||||
db_commit_transaction(db);
|
||||
|
||||
/* This needs to be done outside a transaction, apparently.
|
||||
|
Loading…
Reference in New Issue
Block a user