What it does
DB Migration and Query Optimizer reviews a schema migration before it reaches production, and the slow queries nobody noticed until they mattered. You paste the migration DDL, a slow-query log, optionally an EXPLAIN output and your existing index catalogue, and it audits all of it. The classic case it catches: ADD COLUMN with NOT NULL and no default forces a full table rewrite and takes an ACCESS EXCLUSIVE lock, blocking reads and writes for the duration. The safe rewrite comes back as ordered steps — add the column nullable, backfill in batches, add the constraint NOT VALID, then validate — rather than a warning you have to research yourself. Lock rules are engine-aware, because Postgres and MySQL genuinely differ. On the query side it groups log entries by normalised template and flags an N+1 pattern when the same shape runs three or more times, then extracts WHERE columns no existing index covers and suggests the index, tied to the query template that motivated it. Where this agent is unusually careful is with incomplete evidence. A log entry missing its call count or average latency is excluded from N+1 detection and reported as excluded, never scored on a guessed number. An index suggestion built from such an entry is marked as having incomplete counters and its impact is stated as unranked rather than printed as an invented figure. And the EXPLAIN comparison reads the before numbers from your output, but only shows an after cost when it is genuinely derivable — a sequential scan becoming an index scan on the very table the plan scans. Otherwise it says plainly to re-run EXPLAIN ANALYZE on a read replica. That restraint is the difference between a report you can take to a DBA and one that gets argued with. Each step is callable alone: `analyze_migration_risk` for the lock verdict, `detect_n_plus_one` for the query patterns, `suggest_indexes` for the indexes, `compare_explain` for the plan comparison. `run_full` returns everything plus a ready-to-paste PR description. It is read-only by design — no database access, and no code path that writes anywhere. No connectors and no credentials. Built for backend developers and DBAs who review migrations.
Example prompts
- Will this migration lock the table in production?
- Give me a safe rewrite for this ALTER TABLE
- Find the N+1 patterns in this slow-query log