Browse Source

db: Move db_migrate transaction up one level

We are about to do some more operations before committing, so moving this up
allows us to reuse the same transaction.
travis-debug
Christian Decker 5 years ago
committed by neil saitug
parent
commit
097af493dd
  1. 8
      wallet/db.c
  2. 5
      wallet/test/run-db.c
  3. 2
      wallet/test/run-wallet.c

8
wallet/db.c

@ -905,8 +905,6 @@ static void db_migrate(struct lightningd *ld, struct db *db)
int current, orig, available;
struct db_stmt *stmt;
db_begin_transaction(db);
orig = current = db_get_version(db);
available = ARRAY_SIZE(dbmigrations) - 1;
@ -947,14 +945,18 @@ static void db_migrate(struct lightningd *ld, struct db *db)
tal_free(stmt);
}
db_commit_transaction(db);
}
struct db *db_setup(const tal_t *ctx, struct lightningd *ld)
{
struct db *db = db_open(ctx, ld->wallet_dsn);
db->log = new_log(db, ld->log_book, NULL, "database");
db_begin_transaction(db);
db_migrate(ld, db);
db_commit_transaction(db);
return db;
}

5
wallet/test/run-db.c

@ -73,8 +73,9 @@ static bool test_empty_db_migrate(struct lightningd *ld)
CHECK(db);
db_begin_transaction(db);
CHECK(db_get_version(db) == -1);
db_commit_transaction(db);
db_migrate(ld, db);
db_commit_transaction(db);
db_begin_transaction(db);
CHECK(db_get_version(db) == ARRAY_SIZE(dbmigrations) - 1);
db_commit_transaction(db);
@ -118,9 +119,9 @@ static bool test_vars(struct lightningd *ld)
struct db *db = create_test_db();
char *varname = "testvar";
CHECK(db);
db_migrate(ld, db);
db_begin_transaction(db);
db_migrate(ld, db);
/* Check default behavior */
CHECK(db_get_intvar(db, varname, 42) == 42);

2
wallet/test/run-wallet.c

@ -747,7 +747,9 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx
w->bip32_base) == WALLY_OK);
CHECK_MSG(w->db, "Failed opening the db");
db_begin_transaction(w->db);
db_migrate(ld, w->db);
db_commit_transaction(w->db);
CHECK_MSG(!wallet_err, "DB migration failed");
w->max_channel_dbid = 0;

Loading…
Cancel
Save