Skip to content

Commit

Permalink
db: Switch to new DB asbtraction for DB migrations
Browse files Browse the repository at this point in the history
These do not require the ability to iterate over the result, hence they can be
migrated already.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
  • Loading branch information
cdecker authored and rustyrussell committed Sep 5, 2019
1 parent 50a1af8 commit 093f5bf
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,12 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)

while (current < available) {
current++;
if (dbmigrations[current].sql)
db_exec(__func__, db, "%s", dbmigrations[current].sql);
if (dbmigrations[current].sql) {
struct db_stmt *stmt =
db_prepare_v2(db, dbmigrations[current].sql);
db_exec_prepared_v2(stmt);
db_stmt_free(stmt);
}
if (dbmigrations[current].func)
dbmigrations[current].func(ld, db);
}
Expand Down Expand Up @@ -1270,10 +1274,14 @@ void sqlite3_bind_amount_sat(sqlite3_stmt *stmt, int col,
/* Will apply the current config fee settings to all channels */
void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db)
{
db_exec(__func__, db,
"UPDATE channels SET feerate_base = %u, feerate_ppm = %u;",
ld->config.fee_base,
ld->config.fee_per_satoshi);
struct db_stmt *stmt = db_prepare_v2(
db, SQL("UPDATE channels SET feerate_base = ?, feerate_ppm = ?;"));

db_bind_int(stmt, 0, ld->config.fee_base);
db_bind_int(stmt, 1, ld->config.fee_per_satoshi);

db_exec_prepared_v2(stmt);
db_stmt_free(stmt);
}

void sqlite3_bind_timeabs(sqlite3_stmt *stmt, int col, struct timeabs t)
Expand Down

0 comments on commit 093f5bf

Please sign in to comment.