LaravelYannick Lyn Fatt3 min readintermediate
Difflock: Lint Laravel Migrations and Diff Your Schema
Summary
Difflock is a Laravel package that lints pending migrations against the live database schema, records schema baselines as JSON, and provides CI‑compatible guards to prevent risky migrations. It offers commands for linting, diffing, guarded migration execution, and an MCP server for agent‑driven checks, supporting MySQL, PostgreSQL, SQLite, and more.
- Difflock parses migration files without executing them and compares changes to the actual live schema, flagging destructive ops, column changes, missing indexes, and sensitive columns.
- It can generate a JSON schema snapshot (`schema.json`) to serve as a baseline for drift detection across environments (e.g., staging vs production).
- A dedicated `difflock:migrate` command runs the lint checks before invoking Laravel’s native migration, aborting on findings that exceed a configurable block level.
- CI integration is provided via `difflock:check --ci`, which exits with distinct codes for pass, drift/risky findings, and execution failures.
Database schema changes are a common source of production incidents, especially when migrations are written without full visibility into the current schema. Difflock adds a safety net that catches destructive or unintuitive changes early, integrates with CI pipelines, and provides a reproducible sc…
6/10



