Files
FabledSteward/tests/test_migration_ids.py
T
bvandeusenandClaude Opus 5.5 263560cc94
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m17s
CI / unit (push) Successful in 1m35s
CI / publish (push) Successful in 1m25s
fix(migrations): 0035's revision id fits alembic_version (32 chars) (#5374)
"0035_drop_plugin_catalog_settings" is 33 characters, and
alembic_version.version_num is VARCHAR(32), so the upgrade failed with
"value too long" (CI run 8800, integration). Renamed to
0035_drop_plugin_catalog. tests/test_migration_ids.py now checks every core
and plugin revision id fits, in the unit lane, which never migrates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 13:20:11 -04:00

30 lines
1.1 KiB
Python

"""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}"