跳到正文
cccskills
免费在 GitHub 公开

migration-management

Manage database migrations and schema versioning. Use when planning migrations, version control, rollback strategies, or data transformations for any database paradigm.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(2)

  • SKILL.md6.5 KB
  • references/relational.md4.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Database Migration Management

Overview

Implement robust database migration systems with version control, rollback capabilities, and data transformation strategies. This skill covers universal migration methodology. For paradigm-specific tooling, see references.

When to Use

  • Schema versioning and evolution
  • Data transformations and cleanup
  • Adding/removing tables, columns, collections, or fields
  • Index creation and optimization
  • Migration testing and validation
  • Rollback planning and execution
  • Multi-environment deployments

Paradigm-Specific References

After reading the methodology below, read the reference matching your surface's Databases column in the surface stack map (.agents/instructions/tech-stack.md):

ParadigmReferenceExample Stores
Relationalreferences/relational.mdPostgreSQL, MySQL, SQLite
Documentreferences/document.mdMongoDB, Firestore, CouchDB
Graphreferences/graph.mdSurrealDB, Neo4j, ArangoDB

Universal Migration Principles

1. Bidirectional Migrations

Every migration must have both directions:

  • UP — applies the change
  • DOWN — reverses the change

If a migration cannot be reversed (e.g., data deletion), document this explicitly and require a backup before execution.

2. Migration Ordering

Migrations are sequentially ordered by timestamp or version number:

  • Timestamp format: YYYYMMDD_NNN_description (e.g., 20240115_001_add_phone_to_users)
  • Never reorder or renumber existing migrations
  • Never modify an already-executed migration — create a new one

3. Idempotency

Migrations should be idempotent where possible:

  • Use "IF NOT EXISTS" / "IF EXISTS" guards
  • Check for the presence of the change before applying it
  • Run pre-flight checks before destructive operations

4. Atomic Migrations

Each migration should be a single logical change:

  • One migration = one purpose (add column, create table, transform data)
  • Don't combine unrelated changes
  • Use transactions for multi-statement migrations where supported

Common Migration Patterns

Safe Schema Changes

OperationSafe?Strategy
Add nullable column✅ Always safeAdd with default or NULL
Add NOT NULL column⚠️ Requires backfillAdd nullable → backfill → add constraint
Rename column⚠️ Requires coordinationAdd new → copy data → update app → drop old
Drop column⚠️ Requires coordinationStop reading → deploy → drop column
Add index⚠️ Can lock tableUse concurrent/online index creation
Drop table🔴 DestructiveBackup first, confirm no references

Multi-Phase Migrations

For non-trivial schema changes (rename, type change, restructure):

  1. Phase 1: Expand — Add new structure alongside old
  2. Phase 2: Migrate — Copy/transform data to new structure
  3. Phase 3: Contract — Remove old structure after verification

This pattern prevents downtime and allows rollback at any phase.

Data Transformation Migrations

When transforming data (normalization, cleanup, format changes):

  1. Verify source data — Count records, check constraints
  2. Apply transformation — Batch for large datasets
  3. Validate results — Compare counts, spot-check values
  4. Document irreversibility — If rollback requires backup restore, say so

Rollback Strategies

Per-Migration Rollback

Every migration has a DOWN direction. Execute in reverse order:

  • Migration 5 DOWN
  • Migration 4 DOWN
  • Migration 3 DOWN
  • ... until target version reached

Point-in-Time Recovery

For data-destructive migrations:

  • Require backup before execution
  • Document the backup location
  • Test restore procedure before migration

Blue-Green Schema Changes

For zero-downtime migrations:

  • Run new schema alongside old
  • Application supports both schemas during transition
  • Cut over when new schema is verified
  • Drop old schema after observation period

Testing Migrations

Local Testing

  1. Fresh database — Run all migrations from scratch (empty → current)
  2. Incremental — Run only new migrations on a copy of production
  3. Rollback — Test DOWN migration after UP
  4. Data integrity — Verify constraints hold after migration

Staging Validation

  1. Restore production backup to staging
  2. Run migrations on staging
  3. Verify application works against migrated schema
  4. Run automated tests against staging
  5. Record migration timing for capacity planning

Pre-Production Checklist

  • Tested on local database
  • Tested on staging with production data copy
  • Rollback procedure tested
  • Backup verified before migration
  • Application code compatible with both old and new schema
  • Migration timing measured (acceptable for maintenance window?)
  • Long-running query impact assessed

Production Deployment

Safe Migration Checklist

  • Test migration on production-like database
  • Verify backup exists before migration
  • Schedule during low-traffic window
  • Monitor locks and long-running queries
  • Have rollback plan ready and tested
  • Document all changes
  • Run in transaction when possible
  • Verify data integrity after migration
  • Coordinate application code deployment with migration
  • Notify team of migration window

Post-Migration Verification

  1. Schema check — Verify new structures exist
  2. Data check — Verify data integrity constraints
  3. Application check — Verify application reads/writes correctly
  4. Performance check — Verify query performance hasn't degraded
  5. Monitoring — Watch error rates for 24 hours post-migration

Migration Tracking

Maintain a migration history table (or equivalent) that records:

  • Migration version/ID
  • Migration name/description
  • Execution timestamp
  • Duration
  • Checksum (to detect tampering)
  • Status (applied, rolled back, failed)

Resources

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Audit and improve web accessibility following WCAG 2.1 guidelines. Use when asked to "improve accessibility", "a11y audit", "WCAG compliance", "screen reader support", "keyboard navigation", or "make accessible".

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Structured methodology for adversarial thinking — generating attack scenarios, abuse cases, race conditions, and security edge cases against specs and implementations. Produces spec-level gap items, not code-level fixes.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Orchestrate multiple Antigravity skills through guided workflows for SaaS MVP delivery, security audits, AI agent builds, and browser QA.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Manage API versioning and evolution with URL/header/query strategies, deprecation workflows, breaking change classification, sunset headers, and consumer-driven contract testing. Use when designing versioning strategy, deprecating endpoints, or evolving API contracts.

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Analyzes codebase structure, data flow, module relationships, and key patterns to generate and maintain a living architecture document (ARCHITECTURE.md).

中文简介正在准备中。当前显示原文说明。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

查看 RepairYourTech 的全部技能

报告此技能的问题