mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
db: Wire in the logs into the database so we can give feedback
This commit is contained in:
parent
f5e4a30c8d
commit
712595f0d2
4 changed files with 10 additions and 7 deletions
|
@ -772,7 +772,7 @@ static int db_get_version(struct db *db)
|
|||
/**
|
||||
* db_migrate - Apply all remaining migrations from the current version
|
||||
*/
|
||||
static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
|
||||
static void db_migrate(struct lightningd *ld, struct db *db)
|
||||
{
|
||||
/* Attempt to read the version from the database */
|
||||
int current, orig, available;
|
||||
|
@ -784,12 +784,12 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
|
|||
available = ARRAY_SIZE(dbmigrations) - 1;
|
||||
|
||||
if (current == -1)
|
||||
log_info(log, "Creating database");
|
||||
log_info(db->log, "Creating database");
|
||||
else if (available < current)
|
||||
db_fatal("Refusing to migrate down from version %u to %u",
|
||||
current, available);
|
||||
else if (current != available)
|
||||
log_info(log, "Updating database from version %u to %u",
|
||||
log_info(db->log, "Updating database from version %u to %u",
|
||||
current, available);
|
||||
|
||||
while (current < available) {
|
||||
|
@ -826,7 +826,8 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
|
|||
struct db *db_setup(const tal_t *ctx, struct lightningd *ld, struct log *log)
|
||||
{
|
||||
struct db *db = db_open(ctx, ld->wallet_dsn);
|
||||
db_migrate(ld, db, log);
|
||||
db->log = log;
|
||||
db_migrate(ld, db);
|
||||
return db;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ struct db {
|
|||
/* List of statements that have been created but not executed yet. */
|
||||
struct list_head pending_statements;
|
||||
char *error;
|
||||
|
||||
struct log *log;
|
||||
};
|
||||
|
||||
struct db_query {
|
||||
|
|
|
@ -69,7 +69,7 @@ static bool test_empty_db_migrate(struct lightningd *ld)
|
|||
db_begin_transaction(db);
|
||||
CHECK(db_get_version(db) == -1);
|
||||
db_commit_transaction(db);
|
||||
db_migrate(ld, db, NULL);
|
||||
db_migrate(ld, db);
|
||||
db_begin_transaction(db);
|
||||
CHECK(db_get_version(db) == ARRAY_SIZE(dbmigrations) - 1);
|
||||
db_commit_transaction(db);
|
||||
|
@ -113,7 +113,7 @@ static bool test_vars(struct lightningd *ld)
|
|||
struct db *db = create_test_db();
|
||||
char *varname = "testvar";
|
||||
CHECK(db);
|
||||
db_migrate(ld, db, NULL);
|
||||
db_migrate(ld, db);
|
||||
|
||||
db_begin_transaction(db);
|
||||
/* Check default behavior */
|
||||
|
|
|
@ -772,7 +772,7 @@ 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_migrate(ld, w->db, w->log);
|
||||
db_migrate(ld, w->db);
|
||||
CHECK_MSG(!wallet_err, "DB migration failed");
|
||||
w->max_channel_dbid = 0;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue