Deprecation and Migration

Deprecation and Migration

Guides an agent through deprecating old systems and migrating users safely, including zero-downtime database schema changes using expand and contract.

Skill files1 file
SKILL.md253 lines
1
---
2
name: deprecation-and-migration
3
description: Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.
4
---
5
6
# Deprecation and Migration
7
8
## Overview
9
10
Code is a liability, not an asset. Every line of code has ongoing maintenance cost — bugs to fix, dependencies to update, security patches to apply, and new engineers to onboard. Deprecation is the discipline of removing code that no longer earns its keep, and migration is the process of moving users safely from the old to the new.
11
12
Most engineering organizations are good at building things. Few are good at removing them. This skill addresses that gap.
13
14
## When to Use
15
16
- Replacing an old system, API, or library with a new one
17
- Sunsetting a feature that's no longer needed
18
- Consolidating duplicate implementations
19
- Removing dead code that nobody owns but everybody depends on
20
- Planning the lifecycle of a new system (deprecation planning starts at design time)
21
- Deciding whether to maintain a legacy system or invest in migration
22
23
## Core Principles
24
25
### Code Is a Liability
26
27
Every line of code has ongoing cost: it needs tests, documentation, security patches, dependency updates, and mental overhead for anyone working nearby. The value of code is the functionality it provides, not the code itself. When the same functionality can be provided with less code, less complexity, or better abstractions — the old code should go.
28
29
### Hyrum's Law Makes Removal Hard
30
31
With enough users, every observable behavior becomes depended on — including bugs, timing quirks, and undocumented side effects. This is why deprecation requires active migration, not just announcement. Users can't "just switch" when they depend on behaviors the replacement doesn't replicate.
32
33
### Deprecation Planning Starts at Design Time
34
35
When building something new, ask: "How would we remove this in 3 years?" Systems designed with clean interfaces, feature flags, and minimal surface area are easier to deprecate than systems that leak implementation details everywhere.
36
37
## The Deprecation Decision
38
39
Before deprecating anything, answer these questions:
40
41
```
42
1. Does this system still provide unique value?
43
→ If yes, maintain it. If no, proceed.
44
45
2. How many users/consumers depend on it?
46
→ Quantify the migration scope.
47
48
3. Does a replacement exist?
49
→ If no, build the replacement first. Don't deprecate without an alternative.
50
51
4. What's the migration cost for each consumer?
52
→ If trivially automated, do it. If manual and high-effort, weigh against maintenance cost.
53
54
5. What's the ongoing maintenance cost of NOT deprecating?
55
→ Security risk, engineer time, opportunity cost of complexity.
56
```
57
58
## Compulsory vs Advisory Deprecation
59
60
| Type | When to Use | Mechanism |
61
|------|-------------|-----------|
62
| **Advisory** | Migration is optional, old system is stable | Warnings, documentation, nudges. Users migrate on their own timeline. |
63
| **Compulsory** | Old system has security issues, blocks progress, or maintenance cost is unsustainable | Hard deadline. Old system will be removed by date X. Provide migration tooling. |
64
65
**Default to advisory.** Use compulsory only when the maintenance cost or risk justifies forcing migration. Compulsory deprecation requires providing migration tooling, documentation, and support — you can't just announce a deadline.
66
67
## The Migration Process
68
69
### Step 1: Build the Replacement
70
71
Don't deprecate without a working alternative. The replacement must:
72
73
- Cover all critical use cases of the old system
74
- Have documentation and migration guides
75
- Be proven in production (not just "theoretically better")
76
77
### Step 2: Announce and Document
78
79
```markdown
80
## Deprecation Notice: OldService
81
82
**Status:** Deprecated as of 2025-03-01
83
**Replacement:** NewService (see migration guide below)
84
**Removal date:** Advisory — no hard deadline yet
85
**Reason:** OldService requires manual scaling and lacks observability.
86
NewService handles both automatically.
87
88
### Migration Guide
89
1. Replace `import { client } from 'old-service'` with `import { client } from 'new-service'`
90
2. Update configuration (see examples below)
91
3. Run the migration verification script: `npx migrate-check`
92
```
93
94
### Step 3: Migrate Incrementally
95
96
Migrate consumers one at a time, not all at once. For each consumer:
97
98
```
99
1. Identify all touchpoints with the deprecated system
100
2. Update to use the replacement
101
3. Verify behavior matches (tests, integration checks)
102
4. Remove references to the old system
103
5. Confirm no regressions
104
```
105
106
**The Churn Rule:** If you own the infrastructure being deprecated, you are responsible for migrating your users — or providing backward-compatible updates that require no migration. Don't announce deprecation and leave users to figure it out.
107
108
### Step 4: Remove the Old System
109
110
Only after all consumers have migrated:
111
112
```
113
1. Verify zero active usage (metrics, logs, dependency analysis)
114
2. Remove the code
115
3. Remove associated tests, documentation, and configuration
116
4. Remove the deprecation notices
117
5. Celebrate — removing code is an achievement
118
```
119
120
## Migration Patterns
121
122
### Strangler Pattern
123
124
Run old and new systems in parallel. Route traffic incrementally from old to new. When the old system handles 0% of traffic, remove it.
125
126
```
127
Phase 1: New system handles 0%, old handles 100%
128
Phase 2: New system handles 10% (canary)
129
Phase 3: New system handles 50%
130
Phase 4: New system handles 100%, old system idle
131
Phase 5: Remove old system
132
```
133
134
### Adapter Pattern
135
136
Create an adapter that translates calls from the old interface to the new implementation. Consumers keep using the old interface while you migrate the backend.
137
138
```typescript
139
// Adapter: old interface, new implementation
140
class LegacyTaskService implements OldTaskAPI {
141
constructor(private newService: NewTaskService) {}
142
143
// Old method signature, delegates to new implementation
144
getTask(id: number): OldTask {
145
const task = this.newService.findById(String(id));
146
return this.toOldFormat(task);
147
}
148
149
// Translate the new shape back into what old consumers expect
150
private toOldFormat(task: Task): OldTask {
151
return { id: Number(task.id), title: task.title, done: task.status === 'done' };
152
}
153
}
154
```
155
156
### Feature Flag Migration
157
158
Use feature flags to switch consumers from old to new system one at a time:
159
160
```typescript
161
function getTaskService(userId: string): TaskService {
162
if (featureFlags.isEnabled('new-task-service', { userId })) {
163
return new NewTaskService();
164
}
165
return new OldTaskService();
166
}
167
```
168
169
### Database Schema Migrations (Expand/Contract)
170
171
A schema change is the riskiest migration because the data is the one thing you cannot roll back by reverting a deploy. The failure mode is coupling the schema change to the code change: rename a column in the same release that starts using the new name, and during the rollout window — when old and new code run at once — one of them is querying a column that doesn't exist. The fix is to **never change a column in place**. Migrate in additive phases so old and new code are both valid at every step.
172
173
```
174
EXPAND ──────────────→ MIGRATE ──────────────→ CONTRACT
175
add the new column, backfill existing rows, once no code reads the
176
nullable, alongside dual-write old+new from old column, drop it in
177
the old one the app a later, separate deploy
178
```
179
180
**Worked example — renaming `name` to `full_name`:**
181
182
1. **Expand.** Add `full_name` as nullable. Deploy. (Old code ignores it; nothing breaks.)
183
2. **Dual-write.** App writes both `name` and `full_name` on every insert/update. Deploy.
184
3. **Backfill.** Copy `name → full_name` for existing rows, in batches, so you don't lock the table.
185
4. **Switch reads.** Point the app at `full_name`, keep writing both. Deploy and bake.
186
5. **Contract.** Stop writing `name`, then — in a *separate, later* deploy — drop the column.
187
188
Each step is independently deployable and reversible: if step 4 misbehaves, roll the code back and `full_name` is still being populated. Treat each phase as a thin vertical slice — see the `incremental-implementation` skill.
189
190
**Rules:**
191
- **Additive first, destructive last and alone.** Adds (new nullable column, new table, new index) are safe in any deploy; drops and renames get their own deploy *after* no code references the old shape.
192
- **Every migration has a tested down path.** A migration you can't reverse is a deploy you can't roll back. Write and run the `down` before merging.
193
- **Backfill in batches, off the hot path.** A single `UPDATE` over millions of rows locks the table; chunk it and throttle.
194
- **Build large indexes without blocking writes** (e.g. Postgres `CREATE INDEX CONCURRENTLY`).
195
- **Decouple from code by feature flag** when the cutover is risky, exactly as in the Feature Flag Migration pattern above.
196
197
## Zombie Code
198
199
Zombie code is code that nobody owns but everybody depends on. It's not actively maintained, has no clear owner, and accumulates security vulnerabilities and compatibility issues. Signs:
200
201
- No commits in 6+ months but active consumers exist
202
- No assigned maintainer or team
203
- Failing tests that nobody fixes
204
- Dependencies with known vulnerabilities that nobody updates
205
- Documentation that references systems that no longer exist
206
207
**Response:** Either assign an owner and maintain it properly, or deprecate it with a concrete migration plan. Zombie code cannot stay in limbo — it either gets investment or removal.
208
209
## Common Rationalizations
210
211
| Rationalization | Reality |
212
|---|---|
213
| "It still works, why remove it?" | Working code that nobody maintains accumulates security debt and complexity. Maintenance cost grows silently. |
214
| "Someone might need it later" | If it's needed later, it can be rebuilt. Keeping unused code "just in case" costs more than rebuilding. |
215
| "The migration is too expensive" | Compare migration cost to ongoing maintenance cost over 2-3 years. Migration is usually cheaper long-term. |
216
| "We'll deprecate it after we finish the new system" | Deprecation planning starts at design time. By the time the new system is done, you'll have new priorities. Plan now. |
217
| "Users will migrate on their own" | They won't. Provide tooling, documentation, and incentives — or do the migration yourself (the Churn Rule). |
218
| "We can maintain both systems indefinitely" | Two systems doing the same thing is double the maintenance, testing, documentation, and onboarding cost. |
219
| "Just rename the column, it's one line" | During the rollout, old and new code run together — one will query a column that no longer exists. Expand/contract, never rename in place. |
220
| "I'll add the column and drop the old one in the same migration" | That couples a safe add to a destructive drop. Drops get their own deploy, after no code references the old shape. |
221
| "We'll write the rollback if we need it" | A migration with no down path is a deploy you can't reverse. Write and run the `down` before merging. |
222
223
## Red Flags
224
225
- Deprecated systems with no replacement available
226
- Deprecation announcements with no migration tooling or documentation
227
- "Soft" deprecation that's been advisory for years with no progress
228
- Zombie code with no owner and active consumers
229
- New features added to a deprecated system (invest in the replacement instead)
230
- Deprecation without measuring current usage
231
- Removing code without verifying zero active consumers
232
- A schema change and the code that depends on it shipped in the same deploy
233
- A column renamed or dropped in place rather than via expand/contract
234
- A migration merged with no tested down path, or a backfill that locks the table
235
236
## Verification
237
238
After completing a deprecation:
239
240
- [ ] Replacement is production-proven and covers all critical use cases
241
- [ ] Migration guide exists with concrete steps and examples
242
- [ ] All active consumers have been migrated (verified by metrics/logs)
243
- [ ] Old code, tests, documentation, and configuration are fully removed
244
- [ ] No references to the deprecated system remain in the codebase
245
- [ ] Deprecation notices are removed (they served their purpose)
246
247
After a database schema migration:
248
249
- [ ] The change ships in additive phases (expand → backfill → contract), not a single in-place edit
250
- [ ] Old and new code are both valid against the schema at every deploy step
251
- [ ] Each migration has a tested down path; backfills run in throttled batches
252
- [ ] Destructive steps (drop/rename) ship in their own deploy after no code references the old shape
253

© Addy Osmani · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,241 prompts

More by @OpenSourceBuffGuy

See all
Purple Energy Drink Splash Ad prompt image

Purple Energy Drink Splash Ad

Draws a dramatic splash-photography ad of a purple energy drink can wrapped in headphones, surrounded by ice, berries and frozen liquid arcs.

image-prompt, nano-banana, photorealistic, product-photography, dramatic-lighting, studio-lighting, macro, neon, bokeh, motion-blur, packaging-design, text-rendering, advertising, luxury, moody, night-scene, food-photography, still-life, limited-palette, for-marketers, for-photographers, for-online-sellers, vibrant-colors, cinematic

Tokyo travel vlogger 13 frame candid phone collage prompt image

Tokyo travel vlogger 13 frame candid phone collage

Generates a 13-frame grid collage of a young travel vlogger exploring Tokyo, each frame a different candid phone shot with deliberate flaws.

image-prompt, gpt-image, chatgpt, multi-panel, collage, candid, smartphone-photo, photorealistic, travel, selfie, woman, night-scene, neon, motion-blur, film-grain, cityscape, landmarks, japan, street-photography, social-media-graphic, fashion, bokeh, for-travelers, for-content-creators, long-form, structured-output

Influencer Marketing Strategist prompt image

Influencer Marketing Strategist

Acts as an influencer marketing strategist that helps creators grow their audience, position themselves, price sponsorships and negotiate brand deals.

system-prompt, act-as, coach, influencer-marketing, social-media, monetization, personal-branding, content-creation, negotiation, pricing, marketing, planner, expert-advice, structured-output, xml-tags, guardrails, for-content-creators, for-marketers, encouraging

Reviews

Loading reviews…

Discussion

Loading comments…