- Home
- Skills
- Data & Databases
- Safe Migration & Slow-Query Fixer
Works with the AI Agents you already use
Safe Migration & Slow-Query Fixer
Gate Laravel migrations for production safety (MySQL/PostgreSQL locking, expand-contract, BLOCK/REVIEW/PASS) and find/fix N+1 and slow queries with measured before/after numbers.
Free
Safe Migration & Slow-Query Fixer
Example session with this skill installed
Review the pending migration 2024_10_01_add_index_to_orders_table.php for a PostgreSQL production database with 50M rows.
- Read your context and instructions
- Compiled the safe migration
I have audited the migration against the safety gate for a PostgreSQL environment with 50M rows.
Migration Gate Report
| Rule ID | Result | Evidence | Table size used | Owner |
|---|---|---|---|---|
| M-03 | BLOCK | CREATE INDEX detected on 50M rows without CONCURRENTLY | 50,000,000 | Agent |
| M-07 | BLOCK | withinTransaction is true, but CONCURRENTLY requires it to be false | 50,000,000 | Agent |
| M-08 | PASS | SET lock_timeout = '2s' found at top of migration | 50,000,000 | Agent |
| M-06 | PASS | down() correctly drops the index | 50,000,000 | Agent |
Overall: NO-GO
Unresolved blockers:
- M-03: Plain index creation on a large table will lock the table for writes. Use
->online()or rawCREATE INDEX CONCURRENTLY. - M-07: PostgreSQL cannot create indexes concurrently inside a transaction. Set
public $withinTransaction = false;in the migration class.
Next steps
- Update the migration to use
->online()and set$withinTransaction = false. - Run
php artisan migrate --pretendagain to verify the generated SQL includesCONCURRENTLY. - Re-run this gate for a final PASS.
Connects securely to your tools. The creator never sees your data.
About this skill
Database migrations on production tables often cause downtime through locks, while N+1 queries and missing indexes degrade performance as data grows. This skill provides a rigorous safety gate for Laravel migrations and a measurement-first workflow for fixing slow queries.
What it does
- Migration gating classifies schema changes as PASS, REVIEW, or BLOCK based on production safety rules for MySQL and PostgreSQL.
- Lock prevention enforces fail-fast lock timeouts and engine-specific safe operations like
CONCURRENTLYorALGORITHM=INPLACE. - N+1 detection identifies redundant queries using
Model::preventLazyLoadingand query log analysis. - Performance measurement requires before/after benchmarks for every fix, including query counts and execution time in milliseconds.
- Index optimization analyzes
EXPLAINplans to recommend composite, covering, or partial indexes based on real query shapes.
How it works
- Engine detection identifies the database type and version from
config/database.phpto branch rule logic. - Pre-flight audit records table sizes and runs
migrate --pretendto inspect the raw SQL before execution. - Safety validation checks the migration against a matrix of destructive operations and locking behaviors.
- Performance fix applies eager loading or index changes and verifies the result with at least three benchmark runs.
Frameworks & tools
This skill is built for Laravel applications using MySQL, MariaDB, or PostgreSQL. It utilizes Eloquent, Laravel Telescope, and the standard database migration system.
Why this beats prompting it yourself
Generic prompts often miss engine-specific locking nuances like how PostgreSQL handles foreign keys versus MySQL. This skill enforces a strict "no numbers, no fix" policy that prevents developers from shipping unverified optimizations or hiding N+1 issues behind a cache.
Use cases
- Reviewing a migration that adds a column to a table with millions of rows.
- Fixing an API endpoint that gets slower as the number of related records grows.
- Reverting a migration that lacks a proper
down()method or contains destructive SQL. - Optimizing complex queries by analyzing and improving the
EXPLAINexecution plan.
Known limitations
Does not support live production profiling or load testing. Measurements on local environments may differ from production due to hardware and data volume variance.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 5 days ago
- Free with an Agensi account
Permissions
What's inside
Frequently Asked Questions
New in Data & Databases
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.