mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 14:54:26 +01:00
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:
committed by
Christian Decker
parent
bccd2f8cf4
commit
1eb7e92a30
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user