migrating-code
$
npx mdskill add rileyhilliard/claude-essentials/migrating-codeExecute safe, reversible code migrations without breaking production.
- Handles dependency upgrades, schema changes, and API transitions.
- Depends on test frameworks and monitoring systems for validation.
- Decides execution order using dependency graphs and risk assessments.
- Delivers verified results with rollback options and updated documentation.
SKILL.md
.github/skills/migrating-codeView on GitHub ↗
---
name: migrating-code
description: Safe code migrations with backward compatibility and reversibility. Use when upgrading dependencies, changing database schemas, API versioning, or transitioning between technologies.
---
# Migrating Code
## Core Principles
1. **Never break production** - Backward compatible until fully rolled out
2. **Small, reversible steps** - Each step independently deployable
3. **Test at every stage** - Before, during, and after
4. **Have rollback ready** - Always
## Migration Checklist
```
- [ ] Pre-Migration: Read changelog, identify breaking changes, ensure test coverage
- [ ] During: Small steps, test each, monitor errors, rollback ready
- [ ] Post: Verify tests, check metrics, remove scaffolding, update docs
```
## Database Schema
### Safe Patterns
| Operation | Pattern |
|-----------|---------|
| Add column | Add nullable first → backfill → add constraints |
| Remove column | Stop writes → deploy code that doesn't read → drop column |
| Rename column | Add new → dual-write → backfill → switch reads → drop old |
| Change type | New column → dual-write → migrate in batches → switch → drop |
**Never:** Add NOT NULL without defaults to tables with data.
## API Migrations
### Deprecation Process
1. Add deprecation warnings to old endpoints
2. Document migration path
3. Set and communicate sunset date
4. Monitor usage
5. Remove after usage drops
```json
{
"data": {},
"_warnings": [{
"code": "DEPRECATED_ENDPOINT",
"message": "Use /api/v2/users instead",
"sunset": "2025-06-01"
}]
}
```
## Framework Upgrades
1. **Upgrade to latest minor first** - Get deprecation warnings
2. **Fix warnings** - Before major upgrade
3. **One major at a time** - Don't batch
4. **Test after each step**
### Adapter Pattern for Library Swaps
```typescript
// Wrap library usage
// lib/date.ts
import moment from 'moment';
export const formatDate = (date: Date, format: string) =>
moment(date).format(format);
// Migration: just change the adapter
import { format } from 'date-fns';
export const formatDate = (date: Date, fmt: string) =>
format(date, fmt);
```
## Gradual Rollout
Use feature flags:
```typescript
if (featureFlags.useNewSystem) {
return newService.process(order);
} else {
return legacyService.process(order);
}
```
Roll out: 1% → 10% → 50% → 100% → remove flag
## Common Pitfalls
**Avoid:**
- Big bang migrations
- No rollback plans
- Skipping dual-write phase
- Single large data transactions
- Removing old code before new is proven
**Do:**
- Small, reversible steps
- Test rollback procedures
- Batch large data migrations
- Keep old paths until new verified
More from rileyhilliard/claude-essentials
- architecting-systemsGuides clean, scalable system architecture during the build phase. Use when designing modules, defining boundaries, structuring projects, managing dependencies, or preventing tight coupling and brittleness as systems grow.
- configuring-claudeBest practices for writing Claude Code skills, rules, and CLAUDE.md instructions. Use when creating SKILL.md files, authoring .claude/rules, writing CLAUDE.md project or user instructions, or configuring Claude behavior for a project or team.
- fixing-flaky-testsDiagnose and fix tests that pass in isolation but fail when run concurrently. Covers shared state isolation and resource conflicts. References condition-based-waiting for timing issues.
- handling-errorsPrevents silent failures and context loss in error handling. Use when writing try-catch blocks, designing error propagation, reviewing catch blocks, or implementing Result patterns.
- managing-databasesGuides database architecture decisions for PostgreSQL, DuckDB, Parquet, PGVector, and Neo4j. Use when designing schemas, choosing storage strategies, optimizing queries, tuning maintenance, configuring vector search, modeling graph data, or diagnosing performance issues across OLTP, OLAP, similarity search, and graph workloads.
- managing-pipelinesGuides CI/CD pipeline architecture, security hardening, and deployment strategies for GitHub Actions. Use when designing workflows, securing supply chains, optimizing build performance, configuring deployments, managing infrastructure as code pipelines, or setting up pipeline observability.
- optimizing-performanceMeasure-first performance optimization that balances gains against complexity. Use when addressing slow code, profiling issues, or evaluating optimization trade-offs.
- planning-productsDefines product features from a PM perspective before technical planning begins. Use when scoping new features, writing product specs, defining user problems, choosing what to build, researching existing patterns, or bridging the gap between strategy and implementation. Covers JTBD analysis, competitive research, UX/DX experience definition, and scope negotiation for consumer, B2B, and developer tool products.
- preflight-checksDetect and run project linters, formatters, and type checkers before committing or claiming completion. Auto-detects tools from project config files.
- reading-logsAnalyzes logs efficiently through targeted search and iterative refinement. Use when investigating errors, debugging incidents, or analyzing patterns in application logs.