mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
db: Enable foreign keys and cascade on shachain delete
Should make maintenance a bit easier.
This commit is contained in:
parent
8b7efd01d7
commit
416d6bf860
1 changed files with 9 additions and 5 deletions
14
wallet/db.c
14
wallet/db.c
|
@ -30,11 +30,11 @@ char *dbmigrations[] = {
|
||||||
min_index INTEGER, \
|
min_index INTEGER, \
|
||||||
num_valid INTEGER, \
|
num_valid INTEGER, \
|
||||||
PRIMARY KEY (id));",
|
PRIMARY KEY (id));",
|
||||||
"CREATE TABLE shachain_known ( \
|
"CREATE TABLE shachain_known ( \
|
||||||
shachain_id INTEGER, \
|
shachain_id INTEGER REFERENCES shachains(id) ON DELETE CASCADE, \
|
||||||
pos INTEGER, \
|
pos INTEGER, \
|
||||||
idx INTEGER, \
|
idx INTEGER, \
|
||||||
hash BLOB, \
|
hash BLOB, \
|
||||||
PRIMARY KEY (shachain_id, pos));",
|
PRIMARY KEY (shachain_id, pos));",
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
@ -155,6 +155,10 @@ static struct db *db_open(const tal_t *ctx, char *filename)
|
||||||
tal_add_destructor(db, close_db);
|
tal_add_destructor(db, close_db);
|
||||||
db->in_transaction = false;
|
db->in_transaction = false;
|
||||||
db->err = NULL;
|
db->err = NULL;
|
||||||
|
if (!db_exec(__func__, db, "PRAGMA foreign_keys = ON;")) {
|
||||||
|
fatal("Could not enable foreignkeys on database: %s", db->err);
|
||||||
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue