Skip to content

Stamp the metadata format version and check it on connect - #90

Merged
roed314 merged 2 commits into
roed314:masterfrom
roed-math:meta-version
Jul 21, 2026
Merged

Stamp the metadata format version and check it on connect#90
roed314 merged 2 commits into
roed314:masterfrom
roed-math:meta-version

Conversation

@roed-math

@roed-math roed-math commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #19.

Stacked on #89 (which stacks on #88): based on the join-queries branch. Independent of the other open PRs; merge order is free (pairwise merges verified locally on the full combined tree).

A single-row meta_version table records the version of the metadata layout, with the code's expectation declared as META_VERSION = 1 in base.py next to the _meta_* column definitions it describes.

  • Stamping: _bootstrap_meta (the create=True path) creates and stamps the table. A fresh database is stamped with the current format; a database that already had meta tables predates the stamp and is stamped with the pre-stamp baseline (1) — moving it to a newer format is a deliberate migration, never a side effect of connecting.
  • Checking: every connection compares the stored version against META_VERSION and raises RuntimeError on mismatch, distinguishing a database newer than the code ("upgrade psycodict") from one older ("migrate the meta_* tables"), plus an empty-table case. A database with meta tables but no stamp is checked as format 1 (review round: previously it was accepted blindly, which would have let unstamped format-1 databases slip past a future META_VERSION = 2); a completely fresh database skips the check and gets the existing "connect with create=True" diagnosis.
  • Compatibility today: since the baseline equals the current format, unstamped databases — production LMFDB, devmirror, anything pre-PR — behave exactly as before. Verified against devmirror.

Tests: stamp present and correct after bootstrap; both mismatch directions plus the empty-table case; a stamp-less database connects and create=True stamps it; and a simulated future bump (META_VERSION + 1) rejects an unstamped database and stamps it as 1, not the new version. Suite 547/26 on this branch, ruff clean.

Merge-order note (with the #3150 PR): whichever merges second has one positional conflict at the __init__ tail — keep this PR's check block, then refresh_tables().

🤖 Generated with Claude Code

roed314 and others added 2 commits July 21, 2026 02:36
A single-row meta_version table records the version of the meta_*
layout.  It is created and stamped by the create=True bootstrap (on
fresh databases and, as an upgrade path, on existing ones), and every
connection refuses to run when the stored version does not match,
with messages distinguishing a database that is newer than the code
from one that is older.  Databases from before the stamp existed are
accepted unchanged.  Fixes roed314#19.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A database with meta tables but no meta_version predates the stamp,
which pins its format: it is now checked as format 1 rather than
accepted blindly, so a future format bump rejects it until migrated
instead of letting it slip through -- and create=True stamps it as 1,
the format it actually has, never as the current version as a side
effect of connecting.  Fresh databases still bootstrap at the current
format.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compatibility check for meta tables and code

2 participants