SkillAtlasSkill 详情

database-migration-plan

Your landlord kept your deposit.

审核状态:已审核Quality 80Security 100

复制安装命令

用 Codex 或 Claude 安装复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它先审查 Skill 页面再帮你安装。

复制前请先查看来源、License 和安全提示。

项目 README

来源文件:README.md

抓取于 2026年8月18日

🧠 PM Skills — 1117 Professional Agent Skills for Claude, ChatGPT, Gemini, Cursor, Codex & Hermes

PM Skills — 1117 professional skills your AI assistant can read. Plain markdown, works with Claude, ChatGPT, Gemini, Cursor, and Codex. MIT licensed.

Your landlord kept your deposit. Your mom got a medical bill that makes no sense. You got laid off on a Tuesday. Someone you love died, and no one handed you the checklist.

Generic AI gives you filler for the moments that matter most. PM Skills gives your AI the exact framework a senior professional would use — for 1,117 real tasks, across work and life.

👉 Start with your moment, not the catalogue → Skill Packs

🍼 New parent · 💼 Just laid off · 🌍 New to this country · 👵 Caring for a parent · 🕊️ Losing someone · 💸 Money in crisis · 🔑 Starting over · 🤖 Getting serious about AI

In the official Anthropic plugin directory Stars npm PyPI Skills SkillCheck SkillSpec Security Audit Version License Sponsor Listed in Awesome Claude Skills Skill of the day Free runs served Website & newsletter

What is PM Skills?

PM Skills is an open-source library of 1117 Agent Skills — plain-markdown SKILL.md files that teach an AI assistant to do one professional task to a senior professional's standard, from writing a PRD to decoding a lease or running a blameless postmortem. Each skill bundles the framework, an output template, quality checks, and anti-patterns. It is MIT-licensed and works with Claude, ChatGPT, Gemini, Cursor, and Codex.

Decode a lease before you sign it. Write a PRD your team can execute. Simulate the promotion committee before the real one meets. Check the weather with zero API keys. Generic AI gives you filler; these give you the structure a senior professional actually uses.

Works natively in Claude Code and Hermes Agent, with ready-to-paste exports for ChatGPT, Gemini, Cursor, Codex and 8 more tools. (PM stands for Professional, not just Product Management.)

Claude Code — native ChatGPT exports Gemini exports Cursor, Codex, Windsurf — one command MCP — any client
Telegram bot Slack app Raycast launcher Obsidian plugin n8n connector
Python — pip install pm-skills Hugging Face dataset Docker image on ghcr GitHub Actions

🐣 New here? Pick a door — each takes about 30 seconds

  1. Just looking → open the ▶ Playground and run a skill in your browser. Nothing to install, nothing to sign up for.
  2. You use Claude Code → type /plugin, search pm-skills, install. Done — ask "decode this lease" and watch.
  3. You use anything else → npx pm-claude-skills add and pick your tool from the menu (Cursor, Codex, Windsurf, ChatGPT, Gemini…).
  4. Want the guided tour → browse the searchable catalogue site and subscribe to get an email whenever new skills launch.

Nothing here can scare your setup. A skill is a markdown file your AI reads — no runtime, no telemetry, no accounts. Installing copies text files; uninstalling is deleting them. Skeptical? Good instinct: read one first — it's designed to be read by humans too.

Don't know what to look for? Describe your task in plain words at 🔎 find — "my landlord kept my deposit", "board meeting on Thursday" — and it names the skill.

Subscribe to the PM Skills newsletter

Never miss a new skill. New ones drop regularly — subscribe to the newsletter and get a short email with a real example whenever they launch. No spam, unsubscribe anytime. Prefer no email? Follow via RSS or browse the newsletter archive.


🧠 Not just what to do — how to think

Most skills here answer "do this task." A new family answers "think differently about my life."

LLMs have one big weakness: they're too correct. On open-ended questions they give the safe, average, textbook answer — technically right and completely forgettable. Two new bundles fight that head-on (inspired by parallel-divergent-ideation research):

💭 pm-thinking — think better

Escape the generic answer and stress-test your own decisions:

🎯 pm-focus — get unstuck

ADHD-friendly executive function (useful for everyone):

✨ See it in action

It's not just a folder of files — the whole library is explorable, runnable, and a little bit magic. All of this runs in your browser, free, nothing to install:

The Skill Playground: pick the Executive Update skill, fill in a few notes, hit run, and watch a structured executive briefing stream out — all in the browser
▶ Pick a skill → fill a short form → run it → a senior-grade artifact streams out. No install, your key stays in your browser (or run free with no key).

Galaxy 3D — fly through all 1117 skills as a glowing constellation you orbit and click into
🌌 Galaxy 3D — fly through all 1117 skills as a living constellation. The ones you've run burn brighter.
PM Skills Wrapped — your practice turned into a shareable, Spotify-Wrapped-style story
🎁 Wrapped — your practice, as a shareable story. 100% local — nothing leaves your browser.

▶ Open the Playground to run any of the 1117 skills with your own key — or just browse them all.

💬 What can I ask it to do?

Anything below is a real ask that activates a real skill — say it in your own words, the description does the routing:

🏠 "decode this lease before I sign" → lease-decoder📋 "write the PRD for our referral feature" → prd-template🚨 "blameless postmortem for Friday's outage" → incident-postmortem
💰 "practice my salary negotiation" → salary-negotiation📉 "why is churn up this quarter?" → churn-analysis⚖️ "rank the backlog with RICE" → rice-prioritisation
🛂 "prep me for the visa interview" → the-visa-interview🔨 "is this contractor quote fair?" → home-contractor-quote-decoder🏡 "should we rent or buy?" → rent-vs-buy
📝 "draft my self-review honestly" → performance-review🚀 "are we ready to launch?" → product-launch-checklist📬 "my inbox is 4,000 deep" → email-triage-system

…all 1117 asks live in the catalog.

⚡ Quick start

You want to…Do this
Browse the skillsSKILLS.md — the full catalog · or the searchable web catalog
Install in Claude Code/plugin → search pm-skills (it's in the official Anthropic directory) — or npx pm-claude-skills add --agent claude
Install in Cursor / Codex / Windsurf / Cline…npx pm-claude-skills add --agent cursor (or codex, windsurf, aider, cline, zed…)
Use one skill in ChatGPT / GeminiCopy it from exports/chatgpt/ or exports/gemini/ and paste as instructions
Skills over MCP, in any sessionclaude mcp add pm-skills -- npx -y pm-claude-skills-mcp

No npm install needed — npx pm-claude-skills … always runs the latest. npx pm-claude-skills list shows everything in your terminal. Full per-tool instructions: docs/installation.md.

📚 The skills

Every skill follows the same discipline: what it produces, the inputs it needs, a real framework (severity scales, decision rules — not vibes), a concrete output template, quality checks, and anti-patterns. All 1117 pass the SkillSpec L3 gate and a security audit in CI.

Decoders bundle crestSimulators bundle crestCalculators bundle crestLive data bundle crestCowork bundle crestTokens bundle crestSeatbelt bundle crestEssentials bundle crest
DecodersSimulatorsCalculatorsLive dataCoworkTokensSeatbeltEssentials

Browse all 1,099 → · try one in your browser →

Every category, with examples

For everyone — life's paperwork and decisions

FamilyWhat it doesExamples (of many)
🔍 Decoders (25+)Read the document before you sign it — plain language, 🔴🟡🟢 severity, the money mathlease · medical bill · job offer · severance · insurance policy · contractor quote · timeshare
🎭 SimulatorsFace the adversary early — the real meeting, then an out-of-character debriefsalary negotiation · promotion committee · thesis defense · visa interview · due-diligence call
🧮 CalculatorsDeterministic Python scripts + honest models — assumptions labeled, no false precisionrent vs buy · FIRE number · debt payoff · raise vs jump · daycare vs stay-home
📡 Live data (17)Real-time answers with zero API keys — weather, rates, flights, scores, all over plain curlweather · currency · crypto · flights · earthquakes · is-it-down
🏠 Life adminThe unglamorous logistics, done in orderrelocation · new parent · caregiving · doctor visits · records requests
💼 Career momentsThe weeks that decide yearslayoff kit · resignation kit · PIP response · first 90 days as manager · interview gauntlet
🏛 Dead mentors (5) 🆕History's sharpest operators, resurrected — the real methods from public-domain classics, applied to modern workMachiavelli on office politics · Sun Tzu on picking your fights · Franklin's decision algebra · Marcus Aurelius on bad days · Bennett's 1908 time audit
🏛 Life systems (20) 🆕Navigating the bureaucracies and emergencies people face alone — civic, disability, immigration, disastervoting-navigator · disability-benefit-appeal · arrival-setup · credential-recognition · go-bag-builder · after-the-disaster
🧠 Human edges (20) 🆕The parts of life nobody built tools for — neurodivergence, invisible illness, grief, identity, the hard conversationsmasking-budget · spoon-planner · diagnosis-limbo-kit · coming-out-rehearsal · grief-admin · rabbit-hole-rescue
⚡ New-gen (10) 🆕How the next generation lives and earns — creator deals, clips, D&D, ranked, resale, the attention warcreator-deal-decoder · clip-factory · ttrpg-session-forge · the-vibe-check · ranked-climb-coach · attention-reset
🔮 2027 (10) 🆕Problems you don't have yet, but will — the agent era's operational skillsagent-severance · deepfake-drill · agent-hiring-panel · context-bankruptcy · clone-brief · api-for-yourself · the-org-simulator
🎲 Tabletop (5) 🆕Game night, upgraded — teach, judge, plan, design, and practice the tradesteach-the-game · rules-lawyer · game-night-planner · board-game-designer · tabletop-negotiator
🧾 Freelance & renters & parentsSmall bundles for specific livespricing your services · late invoices · deposit recovery · IEP meetings · students
🎲 Hobbies (12) 🆕Life outside work — the genuinely fun stuffwine pairing · houseplant care · board-game night · D&D campaign · stargazing · chess openings
💪 Wellbeing (12) 🆕Body and mind, sustainably — not another app streakhome workout · sleep reset · habit builder · posture reset · screen-time detox
🔐 Digital self-defense (12) 🆕When your digital life is under attackidentity-theft recovery · phishing triage · account recovery · data-broker removal · doxxing response
👪 Family & relationships (12) 🆕The people who matternew-baby logistics · wedding vows · co-parenting messages · condolences · in-law boundaries
💭 Thinking modes (24) 🆕Change how your AI reasons — escape the generic answer, stress-test decisionsthe-third-answer · five-minds · decision-panel · red-team-my-plan · devils-advocate · poke-holes-in-this
🎯 Focus & executive function (26) 🆕Get unstuck and run your own brain — ADHD-friendly, for everyonewhere-do-i-start · task-to-first-step · overwhelm-triage · the-one-thing · build-my-memory-file · weekly-unstuck
📖 Learning & mastery (10) 🆕Learn anything faster and make it sticklearn-anything-roadmap · feynman-explainer · spaced-repetition-setup · skill-plateau-breaker · deliberate-practice-plan
💰 Wealth-building (10) 🆕Build wealth on purpose — educational, not financial adviceinvesting-for-beginners · index-fund-starter · ask-for-a-raise · first-100k-plan · financial-independence-roadmap
🤝 Social & relationships (10) 🆕The hard conversations and the human onesmake-friends-as-an-adult · networking-for-introverts · boundary-setting-scripts · give-hard-feedback-kindly · repair-after-a-fight
🩺 Caregiving & aging (10) 🆕Care for aging parents and navigate the system — not medical/legal advicemedical-appointment-advocate · care-team-coordinator · caregiver-burnout-check · long-term-care-options · end-of-life-wishes-conversation
🤖 AI-native life (10) 🆕Use AI itself well — the meta-skills that make every tool betterprompt-library-builder · delegate-to-ai · ai-context-primer · spot-ai-mistakes · get-more-from-ai
🤝 Cowork (100)The office knowledge work an AI coworker actually does — the frameworks — the whole bundleemail triage · spreadsheet audit · meeting cost meter · deck outline first · saying no kindly · delegation brief
⚡ Cowork · Live (12)The same jobs, done — Claude Cowork acts on your real data via connectors + sandbox and returns an artifact — the whole bundleinbox triage (live) · meeting prep (live) · spreadsheet audit (live) · deck from doc · thread → decision · PR description (live)

For professionals — 35 fields

Product Management Engineering Marketing & GTM
Customer Success Data & Analytics Leadership & People
Design & UX Legal Finance
Founders Security Government

…plus HR, sales, operations, research, healthcare, educators, writers, social media, and more — the full profession index, or by bundle in plugins/ (121 bundles). Install any bundle: /plugin install pm-decoders@pm-skills.

Meta

Before installing anyone's skills (including these): skill-vetting — a security read for SKILL.md files. The library's own standard lives in SKILLSPEC.md; every skill's level is enforced in CI.

🔍 What does a skill look like?

A skill is a single markdown file with a name, a description that tells the assistant when to activate it, and a body containing the working framework: required inputs, decision rules or severity scales, a concrete output template, quality checks, and anti-patterns. The assistant reads it and gains the judgment; humans can read, audit, and edit the same file. No runtime, no lock-in.

---
name: lease-decoder
description: "Decode a residential lease into plain English and rank the
  clauses that can hurt you. Use when someone asks 'what am I signing'…"
---
## Framework: Severity Scale
- 🔴 Can cost you real money — auto-renewal into a full new term, break
  penalties beyond re-rental costs, deposit conditions written to fail…

That's the whole trick: it's markdown. Your agent reads it and gains the judgment; you can read it too, audit it, edit it, or write your own. No lock-in, no runtime, no telemetry.

💸 What it costs you, and how to prove it

Cut your token bill

The pm-tokens bundle optimizes every stage of your agent's token journey — no API keys, stdlib Python, nothing leaves your machine. Five habits, typically 30–60% off a session's token flow:

# 1. Map the repo instead of reading it (~3% of the cost of reading everything)
python3 skills/repo-map/scripts/repo_map.py .

# 2. Crush bulk before it enters context (98% smaller on uniform JSON; errors always survive)
python3 skills/context-crusher/scripts/context_crush.py --mode json --file response.json

# 3. Measure what anything costs — at YOUR prices, times YOUR call volume
python3 skills/token-cost/scripts/token_cost.py --file CLAUDE.md --price-in 3 --calls 200

Plus the judgment skills: token-diet (output costs 3–5× input — diet it where safe), context-budget (cache-aware layout: stable first, volatile last), and session-handoff (resume at ~5% of transcript size). See your own breakdown in the 🪙 Token Dashboard — paste what rides in your context, get computed per-piece savings, all in-browser. The full how-to: docs/SAVE-TOKENS.md.

🤝 Make the most of the cowork skills

The pm-cowork bundle is 100 skills for the office work an AI coworker actually does. Install it (/plugin install pm-cowork@pm-skills), then — the whole trick — describe your mess, don't name the skill: say "my inbox is 4,000 deep", "nobody reads my status updates", "this spreadsheet came from someone who left" — the right skill activates on the ask.

Start where it hurts:

Your painSay thisThe skill that answers
Drowning in email"triage my inbox and cut the volume at the source"email-triage-system → inbox-unsubscribe-purge
Calendar is all meetings"audit my recurring meetings and price them"standing-meeting-audit + meeting-cost-meter
Inherited a scary spreadsheet"audit this sheet before we trust it"spreadsheet-audit → formula-detangler
Docs get rewritten in review"outline first, get sign-off, then draft"outline-before-prose
Weeks just happen to you"set up my weekly review"weekly-review-ritual — the hub the others plug into

Three habits that compound: (1) The weekly review is the keystone — it feeds task-triage-matrix, deep-work-blocking, and personal-wip-limits automatically. (2) The skills chain on purpose — email-to-tasks feeds the task triage; the meeting audit feeds async-instead; delegation-brief hands off what the triage says to shed — follow the links inside each skill. (3) Teams adopt one norm at a time — start with agenda-or-cancel or working-agreements, let it stick, then add the next; the ten-norms-on-Monday rollout is how none of them survive.

Prove a skill works, and stop paying MCP rent

Two CLI tools for the trust-and-cost problems the ecosystem keeps hand-waving — both keyless-to-inspect, both one command:

# Does your skill actually work? Prove it. Paired A/B — skill on vs off, same tasks,
# REAL token counts from the API's usage fields, optional blind judge, sha-pinned receipt.
npx pm-claude-skills prove --skill ./my-skill --tasks tasks.txt --runs 2 --judge
npx pm-claude-skills prove --skill ./my-skill --tasks tasks.txt --dry-run   # plan + call count, spends nothing

# Your MCP servers are charging you rent. Measure it: per-server token cost,
# unused-in-N-days flags, "disconnect these three, save X tokens per message".
npx pm-claude-skills mcp-audit --connect

prove exists because the ecosystem is full of "65% better!" claims and almost none are measured — it's the honest-broker harness (the JetBrains "advertised 65%, measured 8.5%" story is exactly why). mcp-audit reads your Claude configs, speaks real MCP to each server to count its schema tokens, and scans your session logs for what you actually use. See also the 📊 AI Spend page — every agent's cost (Claude Code, Codex, Copilot) in one meter, all in-browser.

Agent safety: the pm-seatbelt bundle is the pre-flight checklist before an agent touches email, the browser, or files — least-privilege reviews, prompt-injection spotting, and the blast-radius drill for going autonomous. And RFC 0002 — HANDOFF.md is a dead-simple session-handoff convention (your agent, but it remembers Monday) — a file, not a server, with reference hooks.

Quality, not just quantity

  • Every skill passes the SkillSpec L3 gate — structure, framework, quality checks, anti-patterns — enforced in CI on every commit
  • Eval-scored — 208 scored outputs, avg 4.8/5, judged blind
  • Security-audited — a dedicated CI workflow sweeps every skill and script; calculators are stdlib-only and deterministic with byte-exact output tests
  • Honest by design — decoders end with a not-legal-advice line, calculators name what they don't model, simulators debrief out of character, and skills that shouldn't ghostwrite (student statements) coach instead

🎁 Beyond the skills (the bonus material)

The library grew an ecosystem — all optional, all linked from the full showcase:

📄 The one-page cheatsheet — the whole library on one printable poster · ▶ Skill Playground — try any skill in your browser, no install · 📸 the Gallery — the creative side, in screenshots · Anti-Pattern Museum — 2,900+ shareable rules · The Handbook (also a real printed book) · Workflow recipes · Subagents & slash commands · MCP server + REST API · n8n / Slack / Obsidian integrations · The Boardroom · SkillBench · Org Edition · 🇪🇸 🇫🇷 🇨🇳 🇯🇵 translations

Lint your own skills in CI

The validator that keeps these 1,099 honest, as a GitHub Action:

- uses: mohitagw15856/pm-claude-skills@v76
  with:
    path: .claude/skills   # optional — it finds them otherwise

It checks frontmatter, the Use when … trigger clause a model actually matches on, leftover template text, and structure — and annotates each finding inline on the pull request diff, because a finding on the line beats a finding in a log nobody opens. Also available as npx pm-claude-skills skillcheck.

Zero dependencies, no Docker image, no model call.

Companion tools — for the bits a skill shouldn't guess

A skill can tell a model to check the contrast. Only arithmetic can actually check it. Where a question has a right answer rather than a good one, the skill calls out to a tool instead of estimating — both are MIT, zero-dependency, and neither makes a model call, so they cost nothing to run and return the same answer every time.

notugly — design systems that are provably not ugly. #777777 on white is 4.478 and fails AA; #767676 is 4.542 and passes, and no amount of looking at a screenshot separates those. accessibility-audit, design-system-audit, design-handoff-brief, brand-guidelines and the Figma reviews now fill their contrast rows from npx notugly; the MCP server exposes check_contrast directly; and design-system-generate wraps it for the case where there is no design system and something ships on Thursday.

rulebook — 37 games, 203 rulings, and how commonly each house rule is actually played. board-game-night-planner uses it for teach times and for settling the argument, because a rules disagreement is usually two groups who learned it differently and are both partly right.

🆕 Latest

v76.2.1 — SkillCheck as a GitHub Action, and the design skills now compute their contrast numbers instead of estimating them.

Everything else is in the changelog and the releases — a README should say what this is, not what it was.

❓ First-timer questions, straight answers

Is it actually free? Yes — MIT, all 1117 skills, forever. The skills are markdown; there is nothing to gate. Sponsors fund the playground's free model runs, not access.
Do I need an API key? Not to browse, read, install, or use skills inside a tool you already have (Claude Code, ChatGPT, Cursor…). The playground even serves a few sponsor-funded free runs a day. A key only enters the picture for optional extras like running skills from CI.
I'm not a product manager. Is this for me? PM stands for Professional here. Most of the library is decoders for leases and medical bills, salary-negotiation practice, career-moment kits, life admin, and 35 professions from teaching to veterinary. The product-management corner is just where it started.
Will this mess with my existing setup? No. Skills are inert text files in a folder; your assistant reads them when relevant. Remove the folder and it's like they were never there. The CLI never touches anything outside the skills directory it tells you about.
How do I know these are any good? Every skill passes a structural gate (SkillSpec L3) and a security scan in CI; 208 outputs are eval-scored in the open (avg 4.8/5), and the benchmark report publishes the negative findings too. When something's machine-translated or unscored, it's labelled.

🤝 Contributing

The library grows a skill at a time — plant one of your own. One markdown file, one PR.

Add a skill via PR (the standard, CONTRIBUTING), request one via issue, or publish your own repo to the community index and earn the badge. Translations follow the pattern in skills-i18n/.

❤️ Support

If a skill saved you real money or a real mistake, star the repo — it's how others find it. Sponsors fund the playground's free runs and get naming rights, not influence: become a sponsor.

📄 License

MIT — use them, fork them, ship them at work. Skills are judgment, and judgment wants to be free.


Built by Mohit with Claude. 1117 skills · 121 bundles · 35 professions · every commit gated. The long version of this README — every feature, wave, and frontier bet — lives in the Showcase.

DevOps 与部署数据与 AI文档与办公

低风险

  • 来源需自行核对维护者身份。
  • 未检测到明显脚本安装指令。
  • 未检测到明显外部权限要求。
  • 未检测到高风险命令。
  • 扫描发现:0 条。

Codex — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/mohitagw15856/pm-claude-skills.git
  3. 将 "skills/database-migration-plan" 文件夹复制到 Codex 的 skills 目录中。
  4. 重启 Codex 让新的 skill 生效。

Codex — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Codex 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Codex 让新的 skill 生效。

Claude Code — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/mohitagw15856/pm-claude-skills.git
  3. 将 "skills/database-migration-plan" 文件夹复制到 Claude Code 的 skills 目录中。
  4. 重启 Claude Code 让新的 skill 生效。

Claude Code — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Claude Code 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Claude Code 让新的 skill 生效。

Cursor — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/mohitagw15856/pm-claude-skills.git
  3. 将 "skills/database-migration-plan" 文件夹复制到 Cursor 的 skills 目录中。
  4. 重启 Cursor 让新的 skill 生效。

Cursor — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Cursor 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Cursor 让新的 skill 生效。

GitHub Copilot — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/mohitagw15856/pm-claude-skills.git
  3. 将 "skills/database-migration-plan" 文件夹复制到 GitHub Copilot 的 skills 目录中。
  4. 重启 GitHub Copilot 让新的 skill 生效。

GitHub Copilot — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 GitHub Copilot 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 GitHub Copilot 让新的 skill 生效。

Windsurf — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/mohitagw15856/pm-claude-skills.git
  3. 将 "skills/database-migration-plan" 文件夹复制到 Windsurf 的 skills 目录中。
  4. 重启 Windsurf 让新的 skill 生效。

Windsurf — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Windsurf 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Windsurf 让新的 skill 生效。
查看 SKILL.md 原文
name: database-migration-plan
description: "Write a safe, zero-downtime database migration plan for a schema change. Use when asked to plan a database migration, design a zero-downtime schema change, document an expand/contract migration, produce a rollback procedure for a database change, or coordinate a database schema update with a deployment. Produces a structured migration plan covering migration objectives, backward compatibility analysis, expand/contract phase breakdown, exact SQL, rollback steps per phase, data validation queries, and a deployment runbook."

Database Migration Plan Skill

Produce a complete, safe database migration plan for a schema change. A migration plan is not just the SQL — it is a coordinated sequence of steps that ensures the application stays available, data stays consistent, and every step can be rolled back independently.

The expand/contract pattern is the default approach: expand the schema to support both old and new states, migrate the application, then contract to remove the old state. Never combine schema changes and data backfills in a single migration that runs during deployment.

Required Inputs

Ask for these if not already provided:

  • Current schema state — the DDL or description of the table(s) as they are now
  • Target schema state — the DDL or description of what the table(s) should look like after migration
  • Migration reason — why this change is being made (new feature, performance fix, normalization, compliance)
  • Database engine — PostgreSQL, MySQL, SQLite, CockroachDB, etc.
  • Estimated data volume — approximate number of rows in affected tables
  • Deployment constraints — is any downtime allowed? What is the expected traffic level during migration? Are there multiple app instances running?
  • Rollback window — how long after deploy can the team roll back before the migration becomes irreversible?

Output Format


Database Migration Plan: [Migration Name]

Service: [Name] | Team: [Team name] Author: [Name] | Reviewed by: [Name / DBA] Date: [Date] | Target deploy date: [Date] Database engine: [PostgreSQL X.X / MySQL X.X] Ticket: [JIRA-XXX]


1. Migration Overview

What is changing: [1–2 sentences: the specific schema change — e.g. "Adding a non-nullable organisation_id column to the users table and backfilling it from the accounts table."]

Why: [1–2 sentences: the business or technical reason driving the change.]

Migration type: [Additive only / Additive + backfill / Column rename / Column type change / Table restructure / Index change]

Zero-downtime: [Yes — using expand/contract / No — requires maintenance window — state duration]

Estimated migration duration:

  • Expand phase: [~X minutes]
  • Data backfill: [~X minutes/hours — based on X rows at Y rows/second]
  • Contract phase: [~X minutes after app version deployed]

2. Backward Compatibility Analysis

Before writing a single line of SQL, assess whether each change is backward compatible with the currently deployed application code.

ChangeBackward compatible?RiskNotes
[e.g. Add nullable column org_id]YesLowOld app ignores new column
[e.g. Backfill org_id]YesMediumOld app unaffected; new app reads backfilled values
[e.g. Add NOT NULL constraint to org_id]NoHighOld app that inserts without org_id will fail
[e.g. Drop old column account_id]NoHighOld app that reads account_id will fail
[e.g. Add index on org_id]YesLowAdditive; no breaking change
[e.g. Rename column]NoHighNever rename in one step; use expand/contract

Summary: [e.g. "This migration requires the expand/contract pattern across 3 deployment phases because steps 3 and 4 are not backward compatible."]


3. Expand/Contract Phases

Phase Overview

Phase 1 — EXPAND
  Deploy migration: add new column (nullable), create new indexes
  Old app: continues to work (ignores new column)
  New app: not yet deployed
  Duration: [~X min] | Rollback: trivial — drop new column

       │
       ▼

Phase 2 — BACKFILL + DUAL-WRITE
  Deploy app update: writes to both old and new columns
  Run backfill: populate new column for existing rows
  Validate: confirm 100% of rows have non-null new column
  Duration: [~X hours depending on data volume]
  Rollback: deploy previous app version; new column is still nullable

       │
       ▼

Phase 3 — ENFORCE + SWITCH
  Deploy migration: add NOT NULL constraint, drop old column/index
  Deploy app update: reads only from new column
  Duration: [~X min] | Rollback: requires forward-fix (constraint must be dropped first)

       │
       ▼

Phase 4 — CONTRACT (optional cleanup)
  Deploy migration: drop deprecated columns, rename if needed
  Final state matches target schema
  Rollback: not recommended — contract changes are destructive

Phase 1 — Expand Schema

Goal: Add the new column and structures without breaking the existing application. Deploy order: Run migration first, then (optionally) deploy app. Application state: Old app running; no app changes required yet.

-- Migration: 001_add_org_id_to_users.sql
BEGIN;

-- Add nullable column (safe — old app ignores it)
ALTER TABLE users
    ADD COLUMN org_id UUID NULL
        REFERENCES organisations(id) ON DELETE RESTRICT;

-- Add index NOW, not in Phase 3 — building index on large table during Phase 3 is risky
CREATE INDEX CONCURRENTLY users_org_id_idx ON users (org_id);

-- Note: CONCURRENTLY does not lock the table; safe on live traffic
-- Note: Cannot run CONCURRENTLY inside a transaction block; run separately if needed

COMMIT;

Validation after Phase 1:

-- Confirm column exists and is nullable
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'org_id';
-- Expected: is_nullable = 'YES'

-- Confirm index exists
SELECT indexname, indexdef
FROM pg_indexes
WHERE tablename = 'users' AND indexname = 'users_org_id_idx';

Rollback (Phase 1 only):

BEGIN;
DROP INDEX CONCURRENTLY IF EXISTS users_org_id_idx;
ALTER TABLE users DROP COLUMN IF EXISTS org_id;
COMMIT;

Phase 2 — Backfill Existing Data

Goal: Populate the new column for all existing rows before enforcing NOT NULL. When to run: After Phase 1 is live and stable. Can be run as a background job or a one-time script. Application state: Deploy app version that dual-writes to both old and new columns.

App code change required:

// All INSERT and UPDATE operations must now set BOTH old_column and new_column
// until Phase 3 is complete. This ensures new rows are populated during the backfill window.

Backfill script — batch processing:

-- Run in batches to avoid locking. Adjust batch size based on table size and DB load.
-- Target: no single batch takes more than 5 seconds.

DO $$
DECLARE
    batch_size  INT := 1000;
    affected    INT;
BEGIN
    LOOP
        UPDATE users
        SET    org_id = accounts.organisation_id
        FROM   accounts
        WHERE  users.account_id = accounts.id
          AND  users.org_id IS NULL
        LIMIT  batch_size;

        GET DIAGNOSTICS affected = ROW_COUNT;
        EXIT WHEN affected = 0;

        -- Pause between batches to avoid saturating I/O
        PERFORM pg_sleep(0.1);
    END LOOP;
END $$;

Monitoring during backfill:

-- Check progress — run periodically during backfill
SELECT
    COUNT(*) FILTER (WHERE org_id IS NOT NULL) AS backfilled,
    COUNT(*) FILTER (WHERE org_id IS NULL)     AS remaining,
    COUNT(*)                                   AS total,
    ROUND(
        100.0 * COUNT(*) FILTER (WHERE org_id IS NOT NULL) / COUNT(*), 2
    ) AS pct_complete
FROM users;

Backfill completion validation:

-- Must return 0 before proceeding to Phase 3
SELECT COUNT(*) AS unbackfilled_rows
FROM users
WHERE org_id IS NULL;

-- Confirm no new rows written without org_id (dual-write working)
SELECT COUNT(*) AS recent_missing
FROM users
WHERE org_id IS NULL
  AND created_at > now() - INTERVAL '1 hour';

Rollback (Phase 2 — app only):

  • Deploy previous app version (single-write to old column)
  • org_id column remains nullable; no data is lost
  • Backfilled values remain; harmless

Phase 3 — Enforce Constraints

Goal: Add NOT NULL constraint and remove dependency on the old column. Prerequisites: Phase 2 backfill must be 100% complete (zero rows with org_id IS NULL). Deploy order: Run migration, then deploy app version that reads only from org_id.

PostgreSQL — use NOT VALID + VALIDATE for large tables:

-- Step 1: Add constraint as NOT VALID (no full table scan — instant)
ALTER TABLE users
    ADD CONSTRAINT users_org_id_not_null
    CHECK (org_id IS NOT NULL) NOT VALID;

-- Step 2: VALIDATE CONSTRAINT (takes a SHARE UPDATE EXCLUSIVE lock — allows reads and writes)
-- Run this separately, as it can take minutes on large tables
ALTER TABLE users
    VALIDATE CONSTRAINT users_org_id_not_null;

-- Step 3: Once validated, convert to actual NOT NULL
-- (PostgreSQL trusts the validated check constraint — this is instant)
ALTER TABLE users
    ALTER COLUMN org_id SET NOT NULL;

-- Step 4: Drop the now-redundant check constraint
ALTER TABLE users
    DROP CONSTRAINT users_org_id_not_null;

Validation after Phase 3:

-- Confirm NOT NULL is enforced
SELECT column_name, is_nullable
FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'org_id';
-- Expected: is_nullable = 'NO'

-- Test that insert without org_id fails (run in a transaction and roll back)
BEGIN;
INSERT INTO users (email) VALUES ('test@example.com');
-- Expected: ERROR: null value in column "org_id" violates not-null constraint
ROLLBACK;

Rollback (Phase 3):

-- Drop the NOT NULL constraint (restores nullable state)
ALTER TABLE users ALTER COLUMN org_id DROP NOT NULL;
-- Then deploy previous app version (dual-write)
-- Note: Once app code reading the new column is live, rolling back the constraint
-- without rolling back the app will cause issues — plan this carefully.

Phase 4 — Contract (Remove Old Column)

Goal: Remove the old column once the app no longer references it. Prerequisites: Phase 3 fully deployed and stable for at least [X days/hours rollback window]. Warning: This phase is destructive — the old column's data is permanently deleted.

BEGIN;

-- Drop the old column
ALTER TABLE users DROP COLUMN account_id;

-- Drop any indexes that referenced the old column
DROP INDEX IF EXISTS users_account_id_idx;

COMMIT;

Pre-drop validation:

-- Confirm no application queries still reference the old column
-- (Check this in code review and via a search of the codebase before running)
-- grep -r "account_id" app/

-- Confirm the column is safe to drop
SELECT COUNT(*) FROM users WHERE account_id IS NOT NULL;
-- Should be 0 (or irrelevant once new column is canonical)

Rollback: Not straightforward — dropped column data cannot be recovered. Only proceed to Phase 4 after the rollback window has passed and the change is confirmed stable.


4. Data Validation Plan

Run these queries before and after the full migration to confirm data integrity.

Pre-migration baseline:

-- Record these values before any migration step
SELECT COUNT(*)   AS total_users FROM users;
SELECT COUNT(*)   AS total_orgs  FROM organisations;
SELECT MIN(created_at), MAX(created_at) FROM users;

-- Check for any anomalies in the source data before backfill
SELECT COUNT(*) AS users_without_account
FROM users WHERE account_id IS NULL;

Post-backfill integrity check:

-- All users have an org that exists
SELECT COUNT(*) AS orphaned_org_refs
FROM users u
WHERE u.org_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1 FROM organisations o WHERE o.id = u.org_id
  );
-- Expected: 0

-- org_id matches expected value from source column
SELECT COUNT(*) AS mismatched_backfill
FROM users u
JOIN accounts a ON u.account_id = a.id
WHERE u.org_id != a.organisation_id;
-- Expected: 0

-- Row count unchanged (no rows created or deleted by migration)
SELECT COUNT(*) AS total_users_after FROM users;
-- Must match pre-migration baseline

Post-contract final check:

-- Old column is gone
SELECT COUNT(*) FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'account_id';
-- Expected: 0

-- New column is NOT NULL
SELECT is_nullable FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'org_id';
-- Expected: NO

5. Performance Impact Assessment

StepLock typeLock durationTraffic impact
Add nullable columnACCESS EXCLUSIVEMillisecondsNegligible
CREATE INDEX CONCURRENTLYSHARE UPDATE EXCLUSIVEMinutes (proportional to table size)Reads and writes continue
Batch backfillRow-level locks only<5s per batchLow if batches are small
ADD CONSTRAINT NOT VALIDACCESS EXCLUSIVEMillisecondsNegligible
VALIDATE CONSTRAINTSHARE UPDATE EXCLUSIVEMinutesReads and writes continue
ALTER COLUMN SET NOT NULLACCESS EXCLUSIVEMilliseconds (if check constraint validated)Negligible
DROP COLUMNACCESS EXCLUSIVEMillisecondsNegligible

Expected load increase during backfill:

  • DB CPU: [estimated % increase during batch writes]
  • DB I/O: [estimated increase]
  • Monitoring threshold to pause backfill: [e.g. DB CPU > 80% for >2 minutes]

Backfill rate estimate:

  • Table size: [X million rows]
  • Batch size: [1000 rows]
  • Pause between batches: [100ms]
  • Estimated total duration: [X hours at Y rows/second]

6. Deployment Runbook

Follow this checklist on the day of migration. Mark each step as done before proceeding.

Pre-migration (day before):

  • DBA / tech lead has reviewed the migration plan
  • Performance impact assessed; monitoring dashboards ready
  • Backfill script tested on a staging DB with production-scale data
  • Rollback procedure tested on staging
  • On-call engineer briefed; Slack channel [#db-migrations] set up for coordination
  • Maintenance window scheduled (if required)

Phase 1 — Expand (T+0):

  • Take a manual DB snapshot / verify automated backup is recent
  • Run 001_expand_add_org_id.sql on production
  • Run Phase 1 validation queries — confirm pass
  • Deploy app version with dual-write
  • Monitor error rate for [10 minutes]

Phase 2 — Backfill (T+[X hours]):

  • Confirm Phase 1 has been stable for [X hours]
  • Start backfill script in a screen/tmux session
  • Monitor progress via backfill progress query every [5 minutes]
  • Monitor DB CPU and I/O — pause if thresholds exceeded
  • Run completion validation — confirm 0 unbackfilled rows
  • Run integrity checks — confirm 0 orphaned refs, 0 mismatches

Phase 3 — Enforce (T+[X days]):

  • Confirm backfill 100% complete and stable for [X hours]
  • Add NOT VALID constraint
  • Run VALIDATE CONSTRAINT (monitor duration and lock waits)
  • Alter column to NOT NULL
  • Run Phase 3 validation queries
  • Deploy app version reading only from new column
  • Monitor error rate for [30 minutes]

Phase 4 — Contract (T+[X days after rollback window]):

  • Confirm rollback window has passed — no incidents, no rollback needed
  • Search codebase for references to old column — confirm zero
  • Run DROP COLUMN migration
  • Run final integrity checks
  • Close migration ticket; update schema documentation

Quality Checks

  • Every migration phase has an independent rollback procedure — no phase assumes the next one has run
  • Batch backfill script includes a pause between batches to avoid saturating I/O
  • NOT NULL constraints use the NOT VALID + VALIDATE pattern on tables with >100k rows
  • The app dual-write period is explicitly defined — old column writes are not dropped until Phase 3 is deployed
  • Data validation queries include a row count check to confirm no data loss
  • Lock types are identified for every DDL statement — no "should be fine" assumptions
  • The deployment runbook names who runs each step, not just what to run
  • Phase 4 (contract) is explicitly gated on the rollback window passing — not run on the same day as Phase 3

Anti-Patterns

  • Do not combine the expand and contract phases into a single deployment — they must be separated by a deployment cycle
  • Do not run DDL changes without first testing on a production-sized data clone
  • Do not skip the NOT VALID + VALIDATE pattern for constraint additions on large tables — it causes full table locks
  • Do not define a rollback as "restore from backup" — each phase must have an explicit, fast rollback procedure
  • Do not omit dual-write logic during the transition period — removing the old column before all writers are updated causes data loss

发现问题?提交给管理员复核

评分:

评论 (0)

暂无评论,成为第一个评论者吧!