An audit left one question I couldn't answer from memory: can a schedule merge, the update that folds new schedule data into my stored games, move a finished game back to scheduled or live? On a stats site, a final score that turns back into a start time is a bad thing to show anyone.
Pin the current behavior first
The five-value game status (scheduled, in progress, final, postponed or cancelled) on Statpro, my sports stats site, was interpreted in more than a dozen places. Before changing any of them I wrote characterization tests on every piece of code that converts an incoming status and every piece that reads one. A characterization test asserts what the code does today, right or wrong, so a refactor can't change behavior unnoticed. The tests also answered the audit question. Yes, a late merge could do it.
One vocabulary, declared once
The five statuses now live in one shared module with no dependencies. The database enum is generated from it, and the web app and the generator that writes the site's sports facts import it.
The module is small enough to quote whole:
export const GAME_STATUSES = [
"scheduled", "in_progress", "final",
"postponed", "cancelled",
] as const;
export type GameStatus = (typeof GAME_STATUSES)[number];
export function isGameStatus(v: unknown): v is GameStatus {
return GAME_STATUSES.includes(v as GameStatus);
}
The guard drops one field
The guard sits in the game-write path. It reads the game's row after locking it in the database, so no other write can slip in, and if the game is final and the incoming write would set scheduled or live, it drops the status field. The rest of the write still lands, so corrected stats and refreshed odds context aren't lost with it.
Pin the current behavior with tests, then enforce the invariant at the one place every write passes through. Rejecting the whole write would have been simpler, and it would have thrown away good data.