db_migrate: get version inside transaction.

we should never be doing two startups at once, but why take chances?  Plus,
we can then assert that all db calls are in transactions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-11-01 11:40:48 +10:30
committed by Christian Decker
parent bccd2f8cf4
commit 1eb7e92a30

View File

@@ -366,14 +366,16 @@ static int db_migration_count(void)
static bool db_migrate(struct db *db)
{
/* Attempt to read the version from the database */
int current = db_get_version(db);
int available = db_migration_count();
int current, available;
if (!db_begin_transaction(db)) {
/* No need to rollback, we didn't even start... */
return false;
}
current = db_get_version(db);
available = db_migration_count();
while (++current <= available) {
if (!db_exec(__func__, db, "%s", dbmigrations[current]))
goto fail;