ProSkillsLibraryFreePassScan
Data & SQL

Data & SQL · agent skill

Migration Planner

Zero-downtime schema changes, step by step.

What it does

Loads when it is needed

Your agent loads it when the user changes a schema on a live database. It carries 5 rules and reads a profile.md with your details before it starts, so the output matches your brand and project.

Same prompt, with and without

Add NOT NULL to orders.region

Prompt · We need orders.region to be NOT NULL. It's been nullable for years and about 9% of old rows are NULL. Plan it so we don't take the site down.

Table orders: 48M rows, ~120 writes/s, reads constantly. Column: region text NULL (NULL on ~4.3M old rows).
NULL rows can be filled from customers.region via orders.customer_id (customers.region is NOT NULL).
App writes orders from 3 places; the newest release already sets region for new orders only in checkout.
Rails 7.1 with strong_migrations; deploys several times a day, rolling, old and new versions overlap.
Replica lag alert at 30 s.

Profile used: Postgres 15, Rails 7.1 (strong_migrations), 48M-row orders table; migrations named YYYYMMDDHHMMSS_verb_noun

Without the skill
Do this in stages so nothing locks the table for long. The key gotcha: a NOT VALID check constraint is still enforced for new writes, so the app must write region everywhere first. 1. Code first. Only checkout sets region today. Fix the other 2 write paths (default from customer.region) and deploy fully, so no old-version tasks can write NULL. A trigger that fills region from customers on insert is a safer alternative if you can't guarantee that. 2. Add the constraint without scanning: 20251016100000_add_check_orders_region_not_null add_check_constraint :orders, "region IS NOT NULL", name: "orders_region_not_null", validate: false Use a short lock_timeout and retry if it can't get the lock. 3. Backfill separately (rake task or data migration, not in a schema migration), in batches of ~5-10k by id range: UPDATE orders o SET region = c.region FROM customers c WHERE c.id = o.customer_id AND o.region IS NULL AND o.id BETWEEN $1 AND $2; Sleep between batches and pause if replica lag goes above ~10 s (your alert is 30 s). About 4.3M rows means roughly 400-800 batches. 4. validate_check_constraint :orders, name: "orders_region_not_null". This takes a lock that doesn't block reads or writes. …
With the skill
Migration: orders.region NOT NULL Postgres 15, Rails 7.1, 48M rows. Every schema step sets lock_timeout 3s; a timeout means retry, not raise it. 1 Deploy v2: every order write path sets region (customers.region fallback). Lock none. Gate: SELECT count(*) FROM orders WHERE region IS NULL AND created_at > <deploy time> = 0. Rollback: revert deploy. 2 Backfill job, not a migration: UPDATE orders o SET region = c.region FROM customers c WHERE c.id = o.customer_id AND o.id IN (SELECT id FROM orders WHERE region IS NULL ORDER BY id LIMIT 5000 FOR UPDATE SKIP LOCKED); repeat until 0 rows, 200 ms pause, stop if replica lag > 10 s. Row locks only. About 4.3M / 5,000 = 864 batches x (250 ms + 200 ms) = 6.5 min, assuming 250 ms per batch: time it on a restored copy first. Rollback: none needed, idempotent. 3 add_check_constraint :orders, "region IS NOT NULL", name: "orders_region_nn", validate: false. ACCESS EXCLUSIVE, metadata only, under 1 s. Rollback: remove_check_constraint. 4 validate_check_constraint :orders, name: "orders_region_nn" (own migration). SHARE UPDATE EXCLUSIVE, reads and writes continue; scans 48M rows, minutes; set its own statement_timeout. Gate: step 2 finished and the NULL count is 0. 5 change_column_null :orders, :region, false. ACCESS EXCLUSIVE, brief, skips the scan (Postgres 12+ uses the validated check). Rollback: change_column_null :orders, :region, true. 6 remove_check_constraint :orders, name: "orders_region_nn". Brief lock. Risks: a v1 pod writing NULL after step 4 fails its insert, so confirm no v1 pods remain before step 5. Not run anywhere.

Both answers from the same model (Claude sonnet), 2026-10-16. The one without the skill was written in a separate session that never saw it. Shortened where marked with …

Install

One command, in your project

It detects your agent; add --agent all for every agent.

npx proskills-cli add migration-planner --order <order id from your receipt>

Or copy the skill folder (the one holding SKILL.md) into the directory your agent reads, then restart it or start a new session.

AgentThis projectEvery project
Claude Code.claude/skills/~/.claude/skills/
Cursor.agents/skills/ (or .cursor/skills/)~/.cursor/skills/
Codex.agents/skills/~/.agents/skills/
Gemini CLI.agents/skills/ (or .gemini/skills/)~/.gemini/skills/

Changelog

What changed

  • v1.0.0 · 2026-10-16
    • First versioned release: Zero-downtime schema changes, step by step.
    • Scanned 100/100 before release.

Keep it current with npx proskills-cli update; your profile.md is never touched. Everyone who bought it gets the update free and an email when it lands.

Same collection

More from Data & SQL

The scan checks spec compliance, token cost, clarity and security patterns. A clean scan is not a guarantee: static scanners can be evaded. Scan any skill yourself.