Skip to main content

types

Versioned cache records.

Each sub-package is one logical cache table (<name>/) containing one package per schema version (v1/, v2/, ...). A version package vertically integrates the SQLAlchemy ORM (schema.py), the Pydantic record (model.py), the CRUD helpers (store.py), and its inbound migration (migrations.py), and re-exports canonical aliases from its __init__.py. Discovery is driven by bitfount.cache.registry.

The ORM (schema.py) is the single authoring source of truth for a version's table. migrations.py holds an Alembic op-API upgrade(op) / downgrade(op) pair taking v(N-1) -> vN, autogenerated from the ORM diff by python -m bitfount.cache.tools.gen_migration <name> <N> — never hand-authored from scratch. v1 has no predecessor, so its migrations.py defines neither.

Mental model — who owns what (this diverges from canonical Alembic on purpose):

  • The ORM owns table existence. A missing table is created directly from its target-version ORM by ensure_types (implementations/sqlite.py), not by replaying a v1 create_table migration. The additive-only invariant is what makes creating straight at the target safe: every later version is a superset, so lower-version consumers still read/write the table correctly.
  • Migrations own the incremental delta between two existing versions (vN.upgrade = v(N-1) -> vN) — the ALTERs (add/rename/drop/retype) autogen emits. There is no v1 create_table / drop_table: v1 has no prior version, a v1 create would merely duplicate the ORM, and the driver never reaches it (_apply_upgrades walks current+1 .. target with current >= 1).

Consequence: a fresh cache open is one table.create() per type from the ORM — never a full v1..vN chain replay.

Module

Submodules