Skip to main content

Module schema_version

Module schema_version 

Source
Expand description

Schema stamping shared by every Chio operator store.

Each store stamps PRAGMA application_id (to tell a Chio store apart from an unrelated SQLite file) and records its schema revision in a keyed metadata table, then refuses to open a database whose revision is newer than this binary understands or whose contents are not provably ours. The checks run on the open path only, so they add no cost to the append hot path.

Per-store revisions live in a keyed table rather than the database-wide PRAGMA user_version because the sidecar co-locates several stores in one SQLite file. One global pragma cannot represent independent revisions, so a sibling store bumping its schema would otherwise make every unchanged co-located store refuse to open the shared file as if it were from the future.

The application_id is shared by every Chio store, so it proves a file is a Chio store but not which one. To keep a path mistargeted at a sibling store (opening a budget or authority database as a receipt store) from writing this store’s tables into it, a populated database must also carry one of this store’s anchor tables; otherwise it is refused as belonging to another store.

Fail-closed: a foreign, misdirected, or future database is refused before any write, so a rollback to an older binary or a mistargeted path is caught at open rather than after data has been commingled or a newer schema misread.

Enums§

SchemaVersionError
Failure to validate or apply a store’s schema stamp.

Constants§

CHIO_SQLITE_APPLICATION_ID
ASCII “CHIO” as a big-endian i32, stamped into every Chio operator store.

Functions§

check_schema_version
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.
stamp_schema_version
Record this store’s schema revision in keyed metadata after migrations run.