document and check minimum SQLite version

Fixes #147
This commit is contained in:
Scott Lamb 2021-08-19 10:02:25 -07:00
parent dd4a901adb
commit 4e77a26410
4 changed files with 23 additions and 3 deletions

View File

@ -11,6 +11,8 @@ Each release is tagged in Git and on the Docker repository
* fix [#146](https://github.com/scottlamb/moonfire-nvr/issues/146): "init
segment fetch error" when browsers have cached data from `v0.6.4` and
before.
* fix [#147](https://github.com/scottlamb/moonfire-nvr/issues/147): confusing
`nvr init` failures when using very old versions of SQLite.
## `v0.6.5` (2021-08-13)

View File

@ -177,7 +177,9 @@ To build the server, you will need the following C libraries installed:
timeouts for RTSP. For reliable reconnections on error, it's strongly
recommended to use ffmpeg library versions >= 55.1.101.
* [SQLite3](https://www.sqlite.org/).
* [SQLite3](https://www.sqlite.org/), at least version 3.14.0.
(You can skip this if you compile with `--features=bundled` and
don't mind the `moonfire-nvr sql` command not working.)
* [`ncursesw`](https://www.gnu.org/software/ncurses/), the UTF-8 version of
the `ncurses` library.

View File

@ -35,7 +35,7 @@ use crate::schema;
use crate::signal;
use base::clock::{self, Clocks};
use base::strutil::encode_size;
use failure::{bail, format_err, Error};
use failure::{bail, format_err, Error, ResultExt};
use fnv::{FnvHashMap, FnvHashSet};
use hashlink::LinkedHashMap;
use itertools::Itertools;
@ -2117,13 +2117,27 @@ pub(crate) fn set_integrity_pragmas(conn: &mut rusqlite::Connection) -> Result<(
Ok(())
}
pub(crate) fn check_sqlite_version() -> Result<(), Error> {
// SQLite version 3.14.0 introduced the "without rowid" syntax used in the schema.
// https://www.sqlite.org/vtab.html#worid
if rusqlite::version_number() < 3014000 {
bail!(
"SQLite version {} is too old; need at least 3.14.0",
rusqlite::version()
);
}
Ok(())
}
/// Initializes a database.
/// Note this doesn't set journal options, so that it can be used on in-memory databases for
/// test code.
pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
check_sqlite_version()?;
set_integrity_pragmas(conn)?;
let tx = conn.transaction()?;
tx.execute_batch(include_str!("schema.sql"))?;
tx.execute_batch(include_str!("schema.sql"))
.context("unable to create database schema")?;
{
let uuid = ::uuid::Uuid::new_v4();
let uuid_bytes = &uuid.as_bytes()[..];
@ -2221,6 +2235,7 @@ impl<C: Clocks + Clone> Database<C> {
mut conn: rusqlite::Connection,
read_write: bool,
) -> Result<Database<C>, Error> {
check_sqlite_version()?;
set_integrity_pragmas(&mut conn)?;
check_schema_version(&conn)?;

View File

@ -90,6 +90,7 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res
}
pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> {
db::check_sqlite_version()?;
db::set_integrity_pragmas(conn)?;
set_journal_mode(&conn, args.preset_journal)?;
upgrade(args, db::EXPECTED_VERSION, conn)?;