"""Every Alembic revision id fits alembic_version.version_num, a VARCHAR(32). A longer id passes every unit test and fails only when the upgrade writes it: "value too long for type character varying(32)", and the app does not boot (0035, #5374). The unit lane never migrates, so this reads the files. """ import pathlib import re REPO = pathlib.Path(__file__).resolve().parents[1] _REVISION = re.compile(r'^revision(?::[^=]*)?=\s*["\']([^"\']+)["\']', re.M) def revision_ids() -> dict[str, str]: files = [*(REPO / "steward/migrations/versions").glob("*.py"), *(REPO / "plugins").glob("*/migrations/versions/*.py")] found = {} for path in files: m = _REVISION.search(path.read_text()) if m: found[str(path.relative_to(REPO))] = m.group(1) return found def test_every_revision_id_fits_version_num(): ids = revision_ids() assert len(ids) >= 30, ids # core and plugin migrations were found, so the check is real too_long = {path: rev for path, rev in ids.items() if len(rev) > 32} assert not too_long, f"alembic_version.version_num is VARCHAR(32): {too_long}"