mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-02-09 20:58:10 -05:00
make moonfire-nvr sql
enforce integrity
https://github.com/scottlamb/moonfire-nvr/issues/175#issuecomment-1008096087
This commit is contained in:
parent
0406e09ca4
commit
77775a82e5
@ -2107,17 +2107,26 @@ impl LockedDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets pragmas for full database integrity.
|
/// Pragmas for full database integrity.
|
||||||
pub(crate) fn set_integrity_pragmas(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
///
|
||||||
|
/// These are `pub` so that the `moonfire-nvr sql` command can pass to the SQLite3 binary with
|
||||||
|
/// `-cmd`.
|
||||||
|
pub static INTEGRITY_PRAGMAS: [&'static str; 3] = [
|
||||||
// Enforce foreign keys. This is on by default with --features=bundled (as rusqlite
|
// Enforce foreign keys. This is on by default with --features=bundled (as rusqlite
|
||||||
// compiles the SQLite3 amalgamation with -DSQLITE_DEFAULT_FOREIGN_KEYS=1). Ensure it's
|
// compiles the SQLite3 amalgamation with -DSQLITE_DEFAULT_FOREIGN_KEYS=1). Ensure it's
|
||||||
// always on. Note that our foreign keys are immediate rather than deferred, so we have to
|
// always on. Note that our foreign keys are immediate rather than deferred, so we have to
|
||||||
// be careful about the order of operations during the upgrade.
|
// be careful about the order of operations during the upgrade.
|
||||||
conn.execute("pragma foreign_keys = on", params![])?;
|
"pragma foreign_keys = on",
|
||||||
|
|
||||||
// Make the database actually durable.
|
// Make the database actually durable.
|
||||||
conn.execute("pragma fullfsync = on", params![])?;
|
"pragma fullfsync = on",
|
||||||
conn.execute("pragma synchronous = 3", params![])?;
|
"pragma synchronous = 3",
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Sets pragmas for full database integrity.
|
||||||
|
pub(crate) fn set_integrity_pragmas(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
||||||
|
for pragma in INTEGRITY_PRAGMAS {
|
||||||
|
conn.execute(pragma, params![])?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,12 @@ pub fn run(args: Args) -> Result<i32, Error> {
|
|||||||
db.push("?mode=ro");
|
db.push("?mode=ro");
|
||||||
}
|
}
|
||||||
Err(Command::new("sqlite3")
|
Err(Command::new("sqlite3")
|
||||||
|
.args(
|
||||||
|
db::db::INTEGRITY_PRAGMAS
|
||||||
|
.iter()
|
||||||
|
.map(|p| ["-cmd", p])
|
||||||
|
.flatten(),
|
||||||
|
)
|
||||||
.arg(&db)
|
.arg(&db)
|
||||||
.args(&args.arg)
|
.args(&args.arg)
|
||||||
.exec()
|
.exec()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user