|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
|
#include <ccan/tal/str/str.h> |
|
|
#include <ccan/tal/str/str.h> |
|
|
#include <ccan/tal/tal.h> |
|
|
#include <ccan/tal/tal.h> |
|
|
|
|
|
#include <common/version.h> |
|
|
#include <inttypes.h> |
|
|
#include <inttypes.h> |
|
|
#include <lightningd/lightningd.h> |
|
|
#include <lightningd/lightningd.h> |
|
|
#include <lightningd/log.h> |
|
|
#include <lightningd/log.h> |
|
@ -193,6 +194,8 @@ char *dbmigrations[] = { |
|
|
"CREATE INDEX channel_idx ON htlc_sigs (channelid)", |
|
|
"CREATE INDEX channel_idx ON htlc_sigs (channelid)", |
|
|
/* Get rid of OPENINGD entries; we don't put them in db any more */ |
|
|
/* Get rid of OPENINGD entries; we don't put them in db any more */ |
|
|
"DELETE FROM channels WHERE state=1", |
|
|
"DELETE FROM channels WHERE state=1", |
|
|
|
|
|
/* Keep track of db ugprades, for debugging */ |
|
|
|
|
|
"CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);", |
|
|
NULL, |
|
|
NULL, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -386,11 +389,11 @@ static int db_migration_count(void) |
|
|
static void db_migrate(struct db *db, struct log *log) |
|
|
static void db_migrate(struct db *db, struct log *log) |
|
|
{ |
|
|
{ |
|
|
/* Attempt to read the version from the database */ |
|
|
/* Attempt to read the version from the database */ |
|
|
int current, available; |
|
|
int current, orig, available; |
|
|
|
|
|
|
|
|
db_begin_transaction(db); |
|
|
db_begin_transaction(db); |
|
|
|
|
|
|
|
|
current = db_get_version(db); |
|
|
orig = current = db_get_version(db); |
|
|
available = db_migration_count(); |
|
|
available = db_migration_count(); |
|
|
|
|
|
|
|
|
if (current == -1) |
|
|
if (current == -1) |
|
@ -408,6 +411,12 @@ static void db_migrate(struct db *db, struct log *log) |
|
|
/* Finally update the version number in the version table */ |
|
|
/* Finally update the version number in the version table */ |
|
|
db_exec(__func__, db, "UPDATE version SET version=%d;", available); |
|
|
db_exec(__func__, db, "UPDATE version SET version=%d;", available); |
|
|
|
|
|
|
|
|
|
|
|
/* Annotate that we did upgrade, if any. */ |
|
|
|
|
|
if (current != orig) |
|
|
|
|
|
db_exec(__func__, db, |
|
|
|
|
|
"INSERT INTO db_upgrades VALUES (%i, '%s');", |
|
|
|
|
|
orig, version()); |
|
|
|
|
|
|
|
|
db_commit_transaction(db); |
|
|
db_commit_transaction(db); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|