- Home
- Skills
- Data & Databases
- Moonlight Safe Db Migration
More screenshots
Works with the AI Agents you already use
Moonlight Safe Db Migration
Generate and review zero-downtime database migrations with automated lock analysis and multi-phase deploy plans.
Free
Moonlight Safe Db Migration
Example session with this skill installed
/safe-db-migration rename users.fullname to users.display_name without downtime for a PostgreSQL Rails app
- Read your context and instructions
- Compiled the moonlight safe db
I have analyzed the request to rename users.fullname to users.display_name. To ensure zero-downtime, I have decomposed this into a multi-phase plan to maintain compatibility during the rolling deploy.
Zero-Downtime Migration Plan
| Phase | Action | Purpose |
|---|---|---|
| 1. Expand | Add display_name column (nullable) | Allow new app version to write to new column. |
| 2. Backfill | Batch copy fullname to display_name | Populate new column with existing data without locking table. |
| 3. Switch | Update app to read/write display_name | Move application logic to the new schema. |
| 4. Contract | Drop fullname column | Cleanup phase (requires separate approval). |
Migration: 20231027100000_add_display_name_to_users.rb
class AddDisplayNameToUsers < ActiveRecord::Migration[7.0]
def change
# Add column as nullable first to ensure compatibility
add_column :users, :display_name, :string
# Add index concurrently to avoid locking
commit_db_transaction
add_index :users, :display_name, algorithm: :concurrently
end
end
Risk Analysis
- Statement:
add_column - Lock Level: Access Exclusive (short)
- Risk: Low. PostgreSQL adds nullable columns without a table rewrite.
- Statement:
add_index - Lock Level: Share Update Exclusive
- Risk: Minimal. Using
algorithm: :concurrentlyprevents blocking reads/writes.
Verification Query
SELECT count(*) FROM users WHERE display_name IS NULL AND fullname IS NOT NULL;
Next steps
- Review the generated migration and run
rails db:migratelocally. - Execute the provided backfill script in a background worker.
- Deploy the application update that dual-writes to both columns.
Connects securely to your tools. The creator never sees your data.
About this skill
Database schema changes are high-risk operations that often cause downtime through long-held locks or application-level incompatibilities. This skill automates the creation and review of migrations to ensure zero-downtime deploys. It identifies risky DDL statements, manages deployment ordering, and structures changes into safe release phases.
What it does
- Multi-phase planning decomposes destructive changes into expand, backfill, switch, and contract release cycles.
- Risk analysis identifies statements causing table rewrites, exclusive locks, or duration-based failures.
- Migration generation writes idempotent code for tools like Prisma, Alembic, Rails, or TypeORM with appropriate timeouts.
- Verification queries generates SQL to validate data integrity and backfill progress before proceeding.
- Safety reviews audits existing PRs for missing rollbacks, deployment ordering issues, and data loss risks.
How it works
- Discovery scans your repository to identify migration tooling, existing schema, and deployment topology.
- Analysis evaluates the requested change against a risky-operation table to determine locking impact.
- Execution generates the necessary migration files and application code adjustments for dual-writing or reading.
- Validation runs the migration against a local disposable database to report timing and rollback success.
Frameworks & tools
Supports Prisma, TypeORM, Sequelize, Knex, Flyway, Liquibase, Alembic, Rails, and golang-migrate. Works with PostgreSQL, MySQL, and other relational engines.
Why this beats prompting it yourself
Generic prompts often miss the nuances of rolling deploys where old and new app versions coexist. This skill enforces strict DDL timeouts and concurrent index creation that basic LLM outputs typically omit, preventing production outages.
Use cases
- Adding a non-nullable column to a high-traffic table without blocking writes.
- Renaming a column by implementing a dual-write and backfill strategy.
- Adding a unique index concurrently to avoid long-lived access exclusive locks.
- Reviewing a junior developer's migration PR for potential lock contention.
Known limitations
Does not support NoSQL databases. Will not execute migrations on shared, staging, or production environments. Destructive actions require explicit human approval.
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.