Skip to content

Commit

Permalink
stop using cargo pkg version
Browse files Browse the repository at this point in the history
One fewer thing to manage at release time.
  • Loading branch information
scottlamb committed Oct 17, 2023
1 parent ef62ebf commit a76483a
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If applicable, add screenshots to help explain your problem.

**Server (please complete the following information):**
- If using Docker: `docker ps` + `docker images`
- If building from git: `git describe --dirty` + `moonfire-nvr --version`
- If building from git: `moonfire-nvr --version`
- Attach a [log file](https://github.com/scottlamb/moonfire-nvr/blob/master/guide/troubleshooting.md#viewing-moonfire-nvrs-logs). Run with the `RUST_BACKTRACE=1` environment variable set if possible.

**Camera (please complete the following information):**
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ jobs:
extra_args: "--features nightly --benches"
- rust: stable
extra_components: rustfmt
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# `git describe` output gets baked into the binary for `moonfire-nvr --version`.
# Fetch all revs so it can see tag history.
fetch-depth: 0
filter: 'tree:0'
- name: Cache
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -62,9 +67,9 @@ jobs:
strategy:
matrix:
node: [ "14", "16", "18" ]
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ There's no support yet for motion detection, no https/TLS support (you'll
need a proxy server, as described [here](guide/secure.md)), and only a
console-based (rather than web-based) configuration UI.

Moonfire NVR is currently at version 0.7.7. Until version 1.0, there will be no
compatibility guarantees: configuration and storage formats may change from
version to version. There is an [upgrade procedure](guide/schema.md) but it is
not for the faint of heart.
Moonfire NVR is pre-1.0, with will be no compatibility guarantees:
configuration and storage formats may change from version to version. There is
an [upgrade procedure](guide/schema.md) but it is not for the faint of heart.

I hope to add features such as video analytics. In time, we can build
a full-featured hobbyist-oriented multi-camera NVR that requires nothing but
Expand Down
5 changes: 1 addition & 4 deletions guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ Releases are currently a bit manual. From a completely clean git work tree,
1. manually verify the current commit is pushed to github's master branch and
has a green checkmark indicating CI passed.
2. update versions:
* update `server/Cargo.toml` version by hand; run `cargo test --workspace`
to update `Cargo.lock`.
* ensure `README.md` and `CHANGELOG.md` refer to the new version.
2. update version in `CHANGELOG.md`.
3. run commands:
```bash
VERSION=x.y.z
Expand Down
31 changes: 30 additions & 1 deletion server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "moonfire-nvr"
version = "0.7.7"
version = "0.0.0"
authors = ["Scott Lamb <[email protected]>"]
edition = "2021"
resolver = "2"
Expand Down Expand Up @@ -73,6 +73,7 @@ ulid = "1.0.0"
url = "2.1.1"
uuid = { version = "1.1.2", features = ["serde", "std", "v4"] }
flate2 = "1.0.26"
git-version = "0.3.5"

[build-dependencies]
blake3 = "1.0.0"
Expand Down
5 changes: 4 additions & 1 deletion server/db/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ pub fn run(conn: &mut rusqlite::Connection, opts: &Options) -> Result<i32, Error
error!("Schema version is not as expected:\n{}", e);
printed_error = true;
} else {
info!("Schema at expected version {}.", db::EXPECTED_VERSION);
info!(
"Schema at expected version {}.",
db::EXPECTED_SCHEMA_VERSION
);
}

// Compare schemas.
Expand Down
15 changes: 8 additions & 7 deletions server/db/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use tracing::{error, info, trace};
use uuid::Uuid;

/// Expected schema version. See `guide/schema.md` for more information.
pub const EXPECTED_VERSION: i32 = 7;
pub const EXPECTED_SCHEMA_VERSION: i32 = 7;

/// Length of the video index cache.
/// The actual data structure is one bigger than this because we insert before we remove.
Expand Down Expand Up @@ -2238,9 +2238,10 @@ pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
}

/// Gets the schema version from the given database connection.
/// A fully initialized database will return `Ok(Some(version))` where `version` is an integer that
/// can be compared to `EXPECTED_VERSION`. An empty database will return `Ok(None)`. A partially
/// initialized database (in particular, one without a version row) will return some error.
/// A fully initialized database will return `Ok(Some(schema_version))` where `schema_version` is
/// an integer that can be compared to `EXPECTED_SCHEMA_VERSION`. An empty database will return
/// `Ok(None)`. A partially initialized database (in particular, one without a version row) will
/// return some error.
pub fn get_schema_version(conn: &rusqlite::Connection) -> Result<Option<i32>, Error> {
let ver_tables: i32 = conn.query_row_and_then(
"select count(*) from sqlite_master where name = 'version'",
Expand Down Expand Up @@ -2282,19 +2283,19 @@ pub(crate) fn check_schema_version(conn: &rusqlite::Connection) -> Result<(), Er
<https://github.com/scottlamb/moonfire-nvr/blob/master/guide/schema.md>."),
)
};
match ver.cmp(&EXPECTED_VERSION) {
match ver.cmp(&EXPECTED_SCHEMA_VERSION) {
std::cmp::Ordering::Less => bail!(
FailedPrecondition,
msg(
"database schema version {ver} is too old (expected {EXPECTED_VERSION}); \
"database schema version {ver} is too old (expected {EXPECTED_SCHEMA_VERSION}); \
see upgrade instructions in guide/upgrade.md"
),
),
std::cmp::Ordering::Equal => Ok(()),
std::cmp::Ordering::Greater => bail!(
FailedPrecondition,
msg(
"database schema version {ver} is too new (expected {EXPECTED_VERSION}); \
"database schema version {ver} is too new (expected {EXPECTED_SCHEMA_VERSION}); \
must use a newer binary to match"
),
),
Expand Down
46 changes: 28 additions & 18 deletions server/db/upgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! See `guide/schema.md` for more information.
use crate::db::{self, EXPECTED_VERSION};
use crate::db::{self, EXPECTED_SCHEMA_VERSION};
use base::{bail, Error};
use nix::NixPath;
use rusqlite::params;
Expand All @@ -23,8 +23,6 @@ mod v4_to_v5;
mod v5_to_v6;
mod v6_to_v7;

const UPGRADE_NOTES: &str = concat!("upgraded using moonfire-db ", env!("CARGO_PKG_VERSION"));

#[derive(Debug)]
pub struct Args<'a> {
pub sample_file_dir: Option<&'a std::path::Path>,
Expand All @@ -46,7 +44,12 @@ fn set_journal_mode(conn: &rusqlite::Connection, requested: &str) -> Result<(),
Ok(())
}

fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Result<(), Error> {
fn upgrade(
args: &Args,
target_schema_ver: i32,
sw_version: &str,
conn: &mut rusqlite::Connection,
) -> Result<(), Error> {
let upgraders = [
v0_to_v1::run,
v1_to_v2::run,
Expand All @@ -58,33 +61,39 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res
];

{
assert_eq!(upgraders.len(), db::EXPECTED_VERSION as usize);
let old_ver = conn.query_row("select max(id) from version", params![], |row| row.get(0))?;
if old_ver > EXPECTED_VERSION {
assert_eq!(upgraders.len(), db::EXPECTED_SCHEMA_VERSION as usize);
let old_schema_ver =
conn.query_row("select max(id) from version", params![], |row| row.get(0))?;
if old_schema_ver > EXPECTED_SCHEMA_VERSION {
bail!(
FailedPrecondition,
msg("database is at version {old_ver}, later than expected {EXPECTED_VERSION}"),
msg("database is at version {old_schema_ver}, \
later than expected {EXPECTED_SCHEMA_VERSION}"),
);
} else if old_ver < 0 {
} else if old_schema_ver < 0 {
bail!(
FailedPrecondition,
msg("Database is at negative version {old_ver}!")
msg("Database is at negative version {old_schema_ver}!")
);
}
info!(
"Upgrading database from version {} to version {}...",
old_ver, target_ver
"Upgrading database from schema version {} to schema version {}...",
old_schema_ver, target_schema_ver
);
for ver in old_ver..target_ver {
info!("...from version {} to version {}", ver, ver + 1);
for ver in old_schema_ver..target_schema_ver {
info!(
"...from schema version {} to schema version {}",
ver,
ver + 1
);
let tx = conn.transaction()?;
upgraders[ver as usize](args, &tx)?;
tx.execute(
r#"
insert into version (id, unix_time, notes)
values (?, cast(strftime('%s', 'now') as int32), ?)
"#,
params![ver + 1, UPGRADE_NOTES],
params![ver + 1, format!("Upgraded using moonfire-nvr {sw_version}")],
)?;
tx.commit()?;
}
Expand All @@ -93,11 +102,11 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res
Ok(())
}

pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> {
pub fn run(args: &Args, sw_version: &str, conn: &mut rusqlite::Connection) -> Result<(), Error> {
db::check_sqlite_version()?;
db::set_integrity_pragmas(conn)?;
set_journal_mode(conn, args.preset_journal)?;
upgrade(args, EXPECTED_VERSION, conn)?;
upgrade(args, EXPECTED_SCHEMA_VERSION, sw_version, conn)?;

// As in "moonfire-nvr init": try for page_size=16384 and wal for the reasons explained there.
//
Expand Down Expand Up @@ -291,9 +300,10 @@ mod tests {
no_vacuum: false,
},
*ver,
"test",
&mut upgraded,
)
.map_err(|e| err!(e, msg("upgrade to version {ver} failed")))?;
.map_err(|e| err!(e, msg("upgrade to schema version {ver} failed")))?;
if let Some(f) = fresh_sql {
compare(&upgraded, *ver, f)?;
}
Expand Down
1 change: 1 addition & 0 deletions server/src/cmds/upgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn run(args: Args) -> Result<i32, Error> {
preset_journal: &args.preset_journal,
no_vacuum: args.no_vacuum,
},
crate::VERSION,
&mut conn,
)?;
Ok(0)
Expand Down
4 changes: 3 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ mod bundled_ui;

const DEFAULT_DB_DIR: &str = "/var/lib/moonfire-nvr/db";

const VERSION: &str = git_version::git_version!(args = ["--always", "--dirty"]);

/// Moonfire NVR: security camera network video recorder.
#[derive(Bpaf, Debug)]
#[bpaf(options, version)]
#[bpaf(options, version(VERSION))]
enum Args {
// See docstrings of `cmds::*::Args` structs for a description of the respective subcommands.
Check(#[bpaf(external(cmds::check::args))] cmds::check::Args),
Expand Down

0 comments on commit a76483a

Please sign in to comment.