pub fn check_schema_version(
conn: &Connection,
store_key: &str,
supported_version: i32,
legacy_tables: &[&str],
) -> Result<i32, SchemaVersionError>Expand description
Read and validate the schema stamp, returning the on-disk revision so the
caller can run additive migrations up to supported_version. store_key
identifies this store’s revision within the keyed metadata table, so
co-located stores in one shared file each track their own revision.
An unstamped database (application_id == 0) is ambiguous: it is shared by a
freshly created file, a legacy Chio store written before stamping existed,
and countless unrelated SQLite files. It is adopted and stamped only when the
contents prove provenance (the database is empty or carries one of this
store’s legacy_tables); otherwise it is refused as
SchemaVersionError::ForeignDatabase rather than commingling Chio tables
into a foreign file.
A database already stamped with the shared Chio application_id proves it is
a Chio store, but not that it is this store’s. A populated stamped database
must therefore also carry one of legacy_tables, or it is refused as
SchemaVersionError::MismatchedStore so a path aimed at a sibling store’s
database (a budget or authority file) never gets this store’s tables written
into it. An empty stamped database (freshly stamped, tables not yet created)
is always accepted.