Zero-Downtime Migrations

    1

    Expand-contract schema changes — add, backfill, switch, then drop — safe across several deploys.

    Free

    1 useSecurity scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Zero-Downtime Migrations

    Example session with this skill installed

    I need to rename the 'username' column to 'handle' in our production 'profiles' table. It has 5 million rows. Give me the migration plan.

    • Read your context and instructions
    • Compiled the zero-downtime migrations

    I have analyzed the request to rename username to handle on the profiles table. This is a breaking change that requires a 4-step expand-contract cycle to avoid production downtime.

    Database Migration Plan: Rename username to handle

    StepActionTypeNotes
    1Add handle column as NULLAdditiveSafe for existing code.
    2Backfill handle from usernameDataUse chunked updates for 5M rows.
    3Deploy code: Dual-write + Fallback-readCodeWrite to both; read handle (fallback to username).
    4Tighten handle and drop usernameContractRun only after code is fully deployed and verified.

    Migration 1: Add New Column

    -- 20240520_add_handle_to_profiles.sql
    -- Step 1: Add the new column as nullable.
    ALTER TABLE profiles ADD COLUMN handle TEXT NULL;
    

    Backfill Script (Application Level)

    -- Run in batches of 10,000 to avoid long-held locks
    UPDATE profiles 
    SET handle = username 
    WHERE handle IS NULL 
    AND id BETWEEN $start AND $end;
    

    Migration 2: Tighten and Drop

    -- 20240522_tighten_handle_in_profiles.sql
    -- Step 2: Only run after code writes to both columns and backfill is 100% verified.
    ALTER TABLE profiles ALTER COLUMN handle SET NOT NULL;
    
    -- 20240523_drop_username_from_profiles.sql
    -- Step 3: Only run after code no longer references the 'username' column.
    ALTER TABLE profiles DROP COLUMN username;
    

    Next steps

    • Deploy the additive migration and verify the new column exists.
    • Run the chunked backfill script during off-peak hours.
    • Update the User model to handle dual-writes to both fields.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Database schema changes often cause production downtime due to table locks or application crashes during rolling deploys. A single PR that adds a NOT NULL column or renames a field frequently breaks the running version of the app. This skill enforces the expand-contract pattern to ensure zero-downtime migrations.

    What it does

    • Enforces expand-contract by splitting breaking changes into safe, multi-stage deployments.
    • Validates nullability to ensure new columns are added as NULL first to prevent write failures.
    • Audit index creation for large tables, ensuring Postgres CONCURRENTLY usage to avoid ACCESS EXCLUSIVE locks.
    • Plans backfills by designing idempotent, chunked data updates for multi-million row tables.
    • Refines rename strategies by transitioning through dual-writing and fallback reading phases.

    How it works

    1. Classify the change based on the proposed SQL to determine if it requires 1, 2, or 3+ migration files.
    2. Draft the additive migration ensuring it is safe to deploy while the old application code is still running.
    3. Design the backfill and contraction steps, including the necessary application code logic for dual-writing or defensive reading.

    Frameworks & tools

    This skill works with any SQL-based migration system including Prisma, Alembic, Django Migrations, Sequelize, and raw SQL scripts. It includes specific optimizations for Postgres production environments.

    Why this beats prompting it yourself

    Generic AI prompts often suggest one-shot migrations that cause locks or 500 errors during deploys. This skill encodes strict industry-standard safety rules that prioritize uptime over brevity, catching "single-migration smells" before they reach CI.

    Use cases

    • Adding a NOT NULL constraint to a table with existing production data.
    • Renaming a high-traffic column without breaking the current app version.
    • Converting a column data type on a table with millions of rows.
    • Adding unique or secondary indexes to hot tables without blocking writes.

    Known limitations

    Does not provide performance tuning for specific database engine internals beyond locking behavior. Focused on the migration lifecycle rather than query optimization.

    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.

    Focuses on schema migration logic and safety patterns. Does not perform query optimization or engine-level performance tuning.

    How to use

    1. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    1 use

    Times used to date

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 28 days ago

    • Free with an Agensi account

    Permissions

    Write Files
    Listed28 days ago
    Updated25 days ago

    What's inside

    Frequently Asked Questions

    This skill prevents production outages by automatically decomposing risky one-step migrations into a series of safe, "additive-first" deployments, ensuring your database remains compatible with both old and new application code simultaneously.

    The skill is engine-agnostic for standard SQL but includes specialized safety optimizations for PostgreSQL, such as enforcing 'CONCURRENTLY' for index creation and managing lock timeouts.

    You will receive the specialized agent skill configuration, a set of safety-check templates for your CI/CD pipeline, and a guide on interpreting the multi-stage migration plans it generates.

    Yes, the skill designs idempotent, chunked backfill strategies specifically for multi-million row tables to ensure data integrity without exhausting database resources or hitting statement timeouts.

    Simply integrate the skill into your AI agent's workflow by providing your current schema and the desired change; the skill will then output a step-by-step deployment sequence rather than a single file.

    The skill is primarily focused on the deployment lifecycle and locking behavior; it does not provide deep query optimization or server-level parameter tuning (e.g., vacuuming or buffer pool settings).

    New in Data & Databases

    Free