"""The run words and the migrated database, DB-lane: the `job_runs` CHECKs are frozen in a migration, and the model's are built from the enums, so nothing else would notice the two drifting apart until a write of the new word failed in production.""" import re from sqlalchemy import text from app.runstatus import RunStatus, RunTrigger def _words(definition: str) -> set[str]: return set(re.findall(r"'([a-z_]+)'", definition)) def test_the_databases_checks_allow_exactly_the_run_words(db): defs = dict( db.execute( text( "SELECT conname, pg_get_constraintdef(oid) FROM pg_constraint" " WHERE conname LIKE 'ck_job_runs_%'" ) ).all() ) assert _words(defs["ck_job_runs_status"]) == set(RunStatus) assert _words(defs["ck_job_runs_trigger"]) == set(RunTrigger) assert _words(defs["ck_job_runs_finished"]) == {RunStatus.RUNNING}