codingbuddy-rules 2.4.2 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai-rules/CHANGELOG.md +122 -0
- package/.ai-rules/agents/README.md +527 -11
- package/.ai-rules/agents/accessibility-specialist.json +0 -1
- package/.ai-rules/agents/act-mode.json +0 -1
- package/.ai-rules/agents/agent-architect.json +0 -1
- package/.ai-rules/agents/ai-ml-engineer.json +0 -1
- package/.ai-rules/agents/architecture-specialist.json +14 -2
- package/.ai-rules/agents/backend-developer.json +14 -2
- package/.ai-rules/agents/code-quality-specialist.json +0 -1
- package/.ai-rules/agents/data-engineer.json +0 -1
- package/.ai-rules/agents/devops-engineer.json +24 -2
- package/.ai-rules/agents/documentation-specialist.json +0 -1
- package/.ai-rules/agents/eval-mode.json +0 -1
- package/.ai-rules/agents/event-architecture-specialist.json +719 -0
- package/.ai-rules/agents/frontend-developer.json +14 -2
- package/.ai-rules/agents/i18n-specialist.json +0 -1
- package/.ai-rules/agents/integration-specialist.json +11 -1
- package/.ai-rules/agents/migration-specialist.json +676 -0
- package/.ai-rules/agents/mobile-developer.json +0 -1
- package/.ai-rules/agents/observability-specialist.json +747 -0
- package/.ai-rules/agents/performance-specialist.json +24 -2
- package/.ai-rules/agents/plan-mode.json +0 -1
- package/.ai-rules/agents/platform-engineer.json +0 -1
- package/.ai-rules/agents/security-specialist.json +27 -16
- package/.ai-rules/agents/seo-specialist.json +0 -1
- package/.ai-rules/agents/solution-architect.json +0 -1
- package/.ai-rules/agents/technical-planner.json +0 -1
- package/.ai-rules/agents/test-strategy-specialist.json +14 -2
- package/.ai-rules/agents/ui-ux-designer.json +0 -1
- package/.ai-rules/rules/core.md +25 -0
- package/.ai-rules/skills/README.md +35 -0
- package/.ai-rules/skills/database-migration/SKILL.md +531 -0
- package/.ai-rules/skills/database-migration/expand-contract-patterns.md +314 -0
- package/.ai-rules/skills/database-migration/large-scale-migration.md +414 -0
- package/.ai-rules/skills/database-migration/rollback-strategies.md +359 -0
- package/.ai-rules/skills/database-migration/validation-procedures.md +428 -0
- package/.ai-rules/skills/dependency-management/SKILL.md +381 -0
- package/.ai-rules/skills/dependency-management/license-compliance.md +282 -0
- package/.ai-rules/skills/dependency-management/lock-file-management.md +437 -0
- package/.ai-rules/skills/dependency-management/major-upgrade-guide.md +292 -0
- package/.ai-rules/skills/dependency-management/security-vulnerability-response.md +230 -0
- package/.ai-rules/skills/incident-response/SKILL.md +373 -0
- package/.ai-rules/skills/incident-response/communication-templates.md +322 -0
- package/.ai-rules/skills/incident-response/escalation-matrix.md +347 -0
- package/.ai-rules/skills/incident-response/postmortem-template.md +351 -0
- package/.ai-rules/skills/incident-response/severity-classification.md +256 -0
- package/.ai-rules/skills/performance-optimization/CREATION-LOG.md +87 -0
- package/.ai-rules/skills/performance-optimization/SKILL.md +76 -0
- package/.ai-rules/skills/performance-optimization/documentation-template.md +70 -0
- package/.ai-rules/skills/pr-review/SKILL.md +768 -0
- package/.ai-rules/skills/refactoring/SKILL.md +192 -0
- package/.ai-rules/skills/refactoring/refactoring-catalog.md +1377 -0
- package/package.json +1 -1
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-migration
|
|
3
|
+
description: Use when performing database schema changes, data migrations, large table modifications, or when zero-downtime deployment is required - guides systematic, reversible database changes with rollback planning
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Database Migration
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Database migrations are high-risk operations that can cause data loss, service outages, and inconsistencies. Rushed migrations fail; systematic migrations succeed.
|
|
11
|
+
|
|
12
|
+
**Core principle:** ALWAYS have a tested rollback plan before executing any migration. No migration is too small for planning.
|
|
13
|
+
|
|
14
|
+
**Violating the letter of this process is violating the spirit of database migration safety.**
|
|
15
|
+
|
|
16
|
+
## First 5 Minutes Checklist (Emergency Migration)
|
|
17
|
+
|
|
18
|
+
**Use this when urgent schema change needed. Don't think, follow the list.**
|
|
19
|
+
|
|
20
|
+
| Minute | Action | Output |
|
|
21
|
+
|--------|--------|--------|
|
|
22
|
+
| 0-1 | Identify what needs to change and why | `change_classified` |
|
|
23
|
+
| 1-2 | Check if change is reversible | `rollback_possible` or `requires_planning` |
|
|
24
|
+
| 2-3 | Estimate rows affected and lock impact | `impact_assessed` |
|
|
25
|
+
| 3-4 | Create backup of affected tables | `backup_verified` |
|
|
26
|
+
| 4-5 | If >1M rows or DDL lock: STOP, use full process | `proceed` or `escalate` |
|
|
27
|
+
|
|
28
|
+
**After 5 minutes:** Proceed to Phase 2 (Plan) if safe, otherwise follow full process.
|
|
29
|
+
|
|
30
|
+
## The Iron Law
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
NO MIGRATION WITHOUT A TESTED ROLLBACK PLAN FIRST
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
If you haven't verified you can undo the change, you cannot execute the migration.
|
|
37
|
+
|
|
38
|
+
## When to Use
|
|
39
|
+
|
|
40
|
+
Use for ANY database change:
|
|
41
|
+
- Schema modifications (ADD/DROP/ALTER)
|
|
42
|
+
- Large data transformations
|
|
43
|
+
- Index creation or removal
|
|
44
|
+
- Foreign key changes
|
|
45
|
+
- Data type conversions
|
|
46
|
+
- Table splitting or merging
|
|
47
|
+
|
|
48
|
+
**Use this ESPECIALLY when:**
|
|
49
|
+
- Zero-downtime is required (production systems)
|
|
50
|
+
- Table has >1 million rows
|
|
51
|
+
- Change affects foreign key relationships
|
|
52
|
+
- Multiple tables need coordinated changes
|
|
53
|
+
- Rollback must preserve data
|
|
54
|
+
|
|
55
|
+
**Don't skip when:**
|
|
56
|
+
- "It's just adding a column" (NULL vs NOT NULL matters)
|
|
57
|
+
- "We're in a hurry" (rushed migrations cause outages)
|
|
58
|
+
- "It's a small table" (today's small table is tomorrow's large table)
|
|
59
|
+
|
|
60
|
+
## When NOT to Use
|
|
61
|
+
|
|
62
|
+
This skill is for **systematic database migrations**. Don't use it for:
|
|
63
|
+
|
|
64
|
+
- **Local development only** - Experiment freely in dev
|
|
65
|
+
- **Seed data insertion** - Use standard insert scripts
|
|
66
|
+
- **Query optimization** - Use systematic-debugging for investigation
|
|
67
|
+
- **New greenfield tables** - Simple CREATE TABLE is fine
|
|
68
|
+
|
|
69
|
+
**Key distinction:** This skill manages schema and data changes in systems with existing data. For new projects without data, standard migration tools suffice.
|
|
70
|
+
|
|
71
|
+
## The Six Phases
|
|
72
|
+
|
|
73
|
+
You MUST complete each phase before proceeding to the next.
|
|
74
|
+
|
|
75
|
+
```dot
|
|
76
|
+
digraph database_migration {
|
|
77
|
+
rankdir=TB;
|
|
78
|
+
node [shape=box];
|
|
79
|
+
|
|
80
|
+
"1. Assess" -> "2. Plan";
|
|
81
|
+
"2. Plan" -> "3. Prepare";
|
|
82
|
+
"3. Prepare" -> "4. Execute";
|
|
83
|
+
"4. Execute" -> "5. Verify";
|
|
84
|
+
"5. Verify" -> "6. Document";
|
|
85
|
+
|
|
86
|
+
"Skip Phase?" [shape=diamond];
|
|
87
|
+
"2. Plan" -> "Skip Phase?" [style=dashed, label="tempted?"];
|
|
88
|
+
"Skip Phase?" -> "STOP" [label="NO"];
|
|
89
|
+
"STOP" [shape=doublecircle, color=red];
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Phase 1: Assess
|
|
94
|
+
|
|
95
|
+
**Classify the migration:**
|
|
96
|
+
|
|
97
|
+
1. **Identify Migration Type**
|
|
98
|
+
- Schema-only (DDL): ADD COLUMN, CREATE INDEX, etc.
|
|
99
|
+
- Data-only (DML): UPDATE, INSERT, DELETE
|
|
100
|
+
- Combined: Schema + data transformation
|
|
101
|
+
- Destructive: DROP, TRUNCATE, type narrowing
|
|
102
|
+
|
|
103
|
+
2. **Measure Impact**
|
|
104
|
+
- Count rows affected: `SELECT COUNT(*) FROM table`
|
|
105
|
+
- Estimate lock duration
|
|
106
|
+
- Check table size and index count
|
|
107
|
+
- Identify peak traffic windows
|
|
108
|
+
|
|
109
|
+
3. **Classify Risk Level**
|
|
110
|
+
|
|
111
|
+
| Risk | Criteria | Approach |
|
|
112
|
+
|------|----------|----------|
|
|
113
|
+
| **Low** | <100K rows, additive only, nullable | Direct migration |
|
|
114
|
+
| **Medium** | 100K-10M rows, non-destructive | Batched migration |
|
|
115
|
+
| **High** | >10M rows, schema + data | Expand-Contract |
|
|
116
|
+
| **Critical** | Destructive, FK changes | Blue-Green or Shadow |
|
|
117
|
+
|
|
118
|
+
**Completion criteria:**
|
|
119
|
+
- [ ] `migration_type_identified` - DDL/DML/Combined/Destructive
|
|
120
|
+
- [ ] `risk_level_classified` - Low/Medium/High/Critical
|
|
121
|
+
- [ ] `impact_measured` - Row count, lock estimate
|
|
122
|
+
|
|
123
|
+
### Phase 2: Plan
|
|
124
|
+
|
|
125
|
+
**Design the migration strategy:**
|
|
126
|
+
|
|
127
|
+
See `expand-contract-patterns.md` for zero-downtime techniques.
|
|
128
|
+
|
|
129
|
+
1. **Choose Migration Pattern**
|
|
130
|
+
|
|
131
|
+
| Pattern | Use When | Downtime |
|
|
132
|
+
|---------|----------|----------|
|
|
133
|
+
| **Direct** | Low risk, off-peak | Brief |
|
|
134
|
+
| **Batched** | Medium risk, large tables | None |
|
|
135
|
+
| **Expand-Contract** | High risk, zero-downtime required | None |
|
|
136
|
+
| **Blue-Green** | Critical, full schema redesign | Switchover only |
|
|
137
|
+
| **Shadow Table** | Type changes, column renames | Cutover only |
|
|
138
|
+
|
|
139
|
+
1. **Design Rollback Strategy**
|
|
140
|
+
|
|
141
|
+
See `rollback-strategies.md` for detailed procedures.
|
|
142
|
+
|
|
143
|
+
| Change Type | Rollback Approach |
|
|
144
|
+
|-------------|-------------------|
|
|
145
|
+
| ADD COLUMN (nullable) | DROP COLUMN |
|
|
146
|
+
| ADD COLUMN (not null) | Restore from backup or dual-write |
|
|
147
|
+
| DROP COLUMN | Restore from backup (data loss!) |
|
|
148
|
+
| ADD INDEX | DROP INDEX |
|
|
149
|
+
| MODIFY TYPE (widening) | No action needed |
|
|
150
|
+
| MODIFY TYPE (narrowing) | Restore from backup |
|
|
151
|
+
| ADD FK | DROP FK |
|
|
152
|
+
| DROP FK | Re-add FK (verify data integrity) |
|
|
153
|
+
|
|
154
|
+
1. **Create Migration Script**
|
|
155
|
+
- Include UP and DOWN methods
|
|
156
|
+
- Add checkpoints for large migrations
|
|
157
|
+
- Include progress logging
|
|
158
|
+
|
|
159
|
+
**Completion criteria:**
|
|
160
|
+
- [ ] `pattern_selected` - Migration pattern chosen
|
|
161
|
+
- [ ] `rollback_designed` - Rollback procedure documented
|
|
162
|
+
- [ ] `script_created` - Migration script with UP/DOWN
|
|
163
|
+
|
|
164
|
+
### Phase 3: Prepare
|
|
165
|
+
|
|
166
|
+
**Set up for safe execution:**
|
|
167
|
+
|
|
168
|
+
See `validation-procedures.md` for integrity checks.
|
|
169
|
+
|
|
170
|
+
1. **Create Backup**
|
|
171
|
+
- Full table backup for destructive changes
|
|
172
|
+
- Point-in-time backup for data migrations
|
|
173
|
+
- Verify backup is restorable
|
|
174
|
+
|
|
175
|
+
2. **Set Up Monitoring**
|
|
176
|
+
- Query for lock monitoring
|
|
177
|
+
- Replication lag tracking
|
|
178
|
+
- Error rate alerting
|
|
179
|
+
- Progress tracking query
|
|
180
|
+
|
|
181
|
+
3. **Run Pre-Migration Validation**
|
|
182
|
+
|
|
183
|
+
```sql
|
|
184
|
+
-- Example validation queries
|
|
185
|
+
-- Verify row count
|
|
186
|
+
SELECT COUNT(*) as pre_count FROM target_table;
|
|
187
|
+
|
|
188
|
+
-- Verify data integrity
|
|
189
|
+
SELECT COUNT(*) as orphans
|
|
190
|
+
FROM child_table c
|
|
191
|
+
LEFT JOIN parent_table p ON c.parent_id = p.id
|
|
192
|
+
WHERE p.id IS NULL;
|
|
193
|
+
|
|
194
|
+
-- Verify constraints
|
|
195
|
+
SELECT constraint_name, constraint_type
|
|
196
|
+
FROM information_schema.table_constraints
|
|
197
|
+
WHERE table_name = 'target_table';
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
1. **Test Rollback**
|
|
201
|
+
- Execute rollback in staging
|
|
202
|
+
- Verify data is preserved
|
|
203
|
+
- Measure rollback duration
|
|
204
|
+
|
|
205
|
+
**Completion criteria:**
|
|
206
|
+
- [ ] `backup_created` - Backup verified restorable
|
|
207
|
+
- [ ] `monitoring_active` - Dashboards and alerts ready
|
|
208
|
+
- [ ] `pre_validation_passed` - All integrity checks green
|
|
209
|
+
- [ ] `rollback_tested` - Rollback verified in staging
|
|
210
|
+
|
|
211
|
+
### Phase 4: Execute
|
|
212
|
+
|
|
213
|
+
**Run the migration:**
|
|
214
|
+
|
|
215
|
+
See `large-scale-migration.md` for batch processing.
|
|
216
|
+
|
|
217
|
+
1. **Announce Migration**
|
|
218
|
+
- Notify stakeholders
|
|
219
|
+
- Post in incident channel
|
|
220
|
+
- Update status page if needed
|
|
221
|
+
|
|
222
|
+
2. **Execute with Monitoring**
|
|
223
|
+
|
|
224
|
+
For batched migrations:
|
|
225
|
+
```sql
|
|
226
|
+
-- Example batch processing
|
|
227
|
+
DO $$
|
|
228
|
+
DECLARE
|
|
229
|
+
batch_size INT := 10000;
|
|
230
|
+
total_rows INT;
|
|
231
|
+
processed INT := 0;
|
|
232
|
+
BEGIN
|
|
233
|
+
SELECT COUNT(*) INTO total_rows FROM target_table WHERE condition;
|
|
234
|
+
|
|
235
|
+
WHILE processed < total_rows LOOP
|
|
236
|
+
UPDATE target_table
|
|
237
|
+
SET new_column = transform(old_column)
|
|
238
|
+
WHERE id IN (
|
|
239
|
+
SELECT id FROM target_table
|
|
240
|
+
WHERE condition AND new_column IS NULL
|
|
241
|
+
LIMIT batch_size
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
processed := processed + batch_size;
|
|
245
|
+
RAISE NOTICE 'Processed % of % rows', processed, total_rows;
|
|
246
|
+
|
|
247
|
+
-- Brief pause to reduce lock contention
|
|
248
|
+
PERFORM pg_sleep(0.1);
|
|
249
|
+
END LOOP;
|
|
250
|
+
END $$;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
1. **Monitor During Execution**
|
|
254
|
+
- Watch replication lag
|
|
255
|
+
- Monitor lock waits
|
|
256
|
+
- Track error rates
|
|
257
|
+
- Check application health
|
|
258
|
+
|
|
259
|
+
2. **Abort Criteria**
|
|
260
|
+
- Replication lag > 30 seconds
|
|
261
|
+
- Lock wait > 60 seconds
|
|
262
|
+
- Error rate spike > 5%
|
|
263
|
+
- Application errors increasing
|
|
264
|
+
|
|
265
|
+
**Completion criteria:**
|
|
266
|
+
- [ ] `migration_executed` - All changes applied
|
|
267
|
+
- [ ] `no_abort_triggered` - Execution completed without abort
|
|
268
|
+
- [ ] `stakeholders_notified` - Team informed of completion
|
|
269
|
+
|
|
270
|
+
### Phase 5: Verify
|
|
271
|
+
|
|
272
|
+
**Confirm migration success:**
|
|
273
|
+
|
|
274
|
+
1. **Run Post-Migration Validation**
|
|
275
|
+
|
|
276
|
+
```sql
|
|
277
|
+
-- Verify row count matches expectation
|
|
278
|
+
SELECT COUNT(*) as post_count FROM target_table;
|
|
279
|
+
|
|
280
|
+
-- Verify data transformation
|
|
281
|
+
SELECT COUNT(*) as failed_transforms
|
|
282
|
+
FROM target_table
|
|
283
|
+
WHERE new_column IS NULL AND old_column IS NOT NULL;
|
|
284
|
+
|
|
285
|
+
-- Verify referential integrity
|
|
286
|
+
SELECT COUNT(*) as broken_refs
|
|
287
|
+
FROM child_table c
|
|
288
|
+
LEFT JOIN parent_table p ON c.parent_id = p.id
|
|
289
|
+
WHERE p.id IS NULL;
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
1. **Application Health Check**
|
|
293
|
+
- Run smoke tests
|
|
294
|
+
- Verify critical paths work
|
|
295
|
+
- Check error rates normalized
|
|
296
|
+
|
|
297
|
+
2. **Compare Pre/Post Metrics**
|
|
298
|
+
- Row counts match expectations
|
|
299
|
+
- Query performance acceptable
|
|
300
|
+
- No data loss detected
|
|
301
|
+
|
|
302
|
+
**Completion criteria:**
|
|
303
|
+
- [ ] `post_validation_passed` - All integrity checks green
|
|
304
|
+
- [ ] `application_healthy` - Critical paths working
|
|
305
|
+
- [ ] `metrics_verified` - Pre/post comparison acceptable
|
|
306
|
+
|
|
307
|
+
### Phase 6: Document
|
|
308
|
+
|
|
309
|
+
**The migration is NOT complete until documented:**
|
|
310
|
+
|
|
311
|
+
1. **Update Changelog**
|
|
312
|
+
- Note the migration
|
|
313
|
+
- Document any data transformations
|
|
314
|
+
- Record rollback procedure used
|
|
315
|
+
|
|
316
|
+
2. **Update Schema Documentation**
|
|
317
|
+
- Update ERD if applicable
|
|
318
|
+
- Update data dictionary
|
|
319
|
+
- Note any deprecated columns
|
|
320
|
+
|
|
321
|
+
3. **Close Migration Ticket**
|
|
322
|
+
- Link to monitoring during execution
|
|
323
|
+
- Document any issues encountered
|
|
324
|
+
- Record actual vs estimated duration
|
|
325
|
+
|
|
326
|
+
4. **Schedule Cleanup (if needed)**
|
|
327
|
+
- For Expand-Contract: Plan contraction phase
|
|
328
|
+
- For Shadow Table: Plan old table removal
|
|
329
|
+
- Set reminder for cleanup deadline
|
|
330
|
+
|
|
331
|
+
**Completion criteria:**
|
|
332
|
+
- [ ] `changelog_updated` - Migration documented
|
|
333
|
+
- [ ] `schema_docs_updated` - Documentation current
|
|
334
|
+
- [ ] `ticket_closed` - Migration ticket resolved
|
|
335
|
+
- [ ] `cleanup_scheduled` - Follow-up tasks created
|
|
336
|
+
|
|
337
|
+
## Red Flags - STOP and Follow Process
|
|
338
|
+
|
|
339
|
+
If you catch yourself thinking:
|
|
340
|
+
- "Just run the migration, we can fix issues later"
|
|
341
|
+
- "It's only adding a column, no need to plan"
|
|
342
|
+
- "We don't have time for a rollback plan"
|
|
343
|
+
- "The table is small enough, skip batching"
|
|
344
|
+
- "We can restore from backup if needed" (without testing)
|
|
345
|
+
- "The migration ran fine in staging"
|
|
346
|
+
- "Let's do it during low traffic, should be fine"
|
|
347
|
+
- "Skip validation, we trust the transformation"
|
|
348
|
+
|
|
349
|
+
**ALL of these mean: STOP. Return to Phase 2.**
|
|
350
|
+
|
|
351
|
+
## Common Rationalizations
|
|
352
|
+
|
|
353
|
+
| Excuse | Reality |
|
|
354
|
+
|--------|---------|
|
|
355
|
+
| "It's just a nullable column" | Nullable columns become NOT NULL. Plan for it. |
|
|
356
|
+
| "Table has only 100K rows" | Tables grow. Build habits for when it's 100M. |
|
|
357
|
+
| "Staging worked fine" | Production has different data, scale, and traffic patterns. |
|
|
358
|
+
| "We can restore from backup" | Backup restore = downtime. Test it, measure it. |
|
|
359
|
+
| "It's off-peak hours" | Off-peak is when batch jobs run. Verify traffic patterns. |
|
|
360
|
+
| "Migration tool handles rollback" | Tools generate rollback, not verify it. Test manually. |
|
|
361
|
+
| "We've done this before" | Past success doesn't guarantee future success. Follow process. |
|
|
362
|
+
| "Business is pressuring us" | Outages cost more than delays. Process protects everyone. |
|
|
363
|
+
|
|
364
|
+
## Quick Reference
|
|
365
|
+
|
|
366
|
+
| Phase | Key Activities | Verification Key |
|
|
367
|
+
|-------|---------------|------------------|
|
|
368
|
+
| **1. Assess** | Type, impact, risk level | `risk_level_classified` |
|
|
369
|
+
| **2. Plan** | Pattern, rollback, script | `rollback_designed` |
|
|
370
|
+
| **3. Prepare** | Backup, monitoring, test rollback | `rollback_tested` |
|
|
371
|
+
| **4. Execute** | Announce, batch, monitor | `migration_executed` |
|
|
372
|
+
| **5. Verify** | Validation, health, metrics | `post_validation_passed` |
|
|
373
|
+
| **6. Document** | Changelog, schema docs, cleanup | `ticket_closed` |
|
|
374
|
+
|
|
375
|
+
## Risk-Based Response Times
|
|
376
|
+
|
|
377
|
+
| Risk Level | Max Duration | Rollback Window | Required Approvals |
|
|
378
|
+
|------------|--------------|-----------------|-------------------|
|
|
379
|
+
| **Low** | 1 hour | 24 hours | 1 reviewer |
|
|
380
|
+
| **Medium** | 4 hours | 72 hours | 2 reviewers |
|
|
381
|
+
| **High** | 1 day | 1 week | Tech lead + DBA |
|
|
382
|
+
| **Critical** | 1 week | 2 weeks | Architecture review |
|
|
383
|
+
|
|
384
|
+
## CI/CD Integration
|
|
385
|
+
|
|
386
|
+
Database migrations require careful coordination with deployment pipelines.
|
|
387
|
+
|
|
388
|
+
### Environment Progression
|
|
389
|
+
|
|
390
|
+
**Always progress: Dev → Staging → Production**
|
|
391
|
+
|
|
392
|
+
| Environment | Purpose | Migration Timing | Approval |
|
|
393
|
+
|-------------|---------|------------------|----------|
|
|
394
|
+
| **Dev** | Experiment freely | On commit | None |
|
|
395
|
+
| **Staging** | Verify with prod-like data | Pre-deploy | Auto |
|
|
396
|
+
| **Production** | Real execution | During deploy window | Manual |
|
|
397
|
+
|
|
398
|
+
**Key principle:** Migrations that pass staging with production-like data volume succeed in production.
|
|
399
|
+
|
|
400
|
+
### Pipeline Integration Patterns
|
|
401
|
+
|
|
402
|
+
**1. Pre-Deploy Migration (Recommended)**
|
|
403
|
+
|
|
404
|
+
```yaml
|
|
405
|
+
# CI/CD pipeline example
|
|
406
|
+
stages:
|
|
407
|
+
- test
|
|
408
|
+
- migrate-staging
|
|
409
|
+
- validate-staging
|
|
410
|
+
- approve-production
|
|
411
|
+
- migrate-production
|
|
412
|
+
- deploy-application
|
|
413
|
+
- validate-production
|
|
414
|
+
|
|
415
|
+
migrate-production:
|
|
416
|
+
script:
|
|
417
|
+
- ./run-migration.sh --env production
|
|
418
|
+
- ./validate-migration.sh --env production
|
|
419
|
+
when: manual # Require explicit approval
|
|
420
|
+
allow_failure: false
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
**2. Application-Driven Migration (ORM Tools)**
|
|
424
|
+
|
|
425
|
+
```yaml
|
|
426
|
+
# For ORM-managed migrations (Prisma, TypeORM, Django, Rails)
|
|
427
|
+
deploy-production:
|
|
428
|
+
script:
|
|
429
|
+
# Backup before ORM migration
|
|
430
|
+
- ./backup-database.sh
|
|
431
|
+
# Run ORM migration with timeout
|
|
432
|
+
- timeout 30m npx prisma migrate deploy
|
|
433
|
+
# Validate after migration
|
|
434
|
+
- ./validate-schema.sh
|
|
435
|
+
on_failure:
|
|
436
|
+
- ./alert-oncall.sh "Migration failed"
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### ORM Migration Tool Guidelines
|
|
440
|
+
|
|
441
|
+
| Tool | Migration Command | Rollback Command | Notes |
|
|
442
|
+
|------|-------------------|------------------|-------|
|
|
443
|
+
| **Prisma** | `prisma migrate deploy` | Manual or `prisma migrate reset` | No auto-rollback in prod |
|
|
444
|
+
| **TypeORM** | `typeorm migration:run` | `typeorm migration:revert` | Revert runs DOWN method |
|
|
445
|
+
| **Django** | `python manage.py migrate` | `python manage.py migrate app 00XX` | Specify target migration |
|
|
446
|
+
| **Rails** | `rails db:migrate` | `rails db:rollback STEP=1` | STEP controls rollback depth |
|
|
447
|
+
| **Flyway** | `flyway migrate` | `flyway undo` (Teams only) | Undo requires paid version |
|
|
448
|
+
| **Liquibase** | `liquibase update` | `liquibase rollback` | Requires rollback tags |
|
|
449
|
+
|
|
450
|
+
**ORM Best Practices:**
|
|
451
|
+
- Always generate DOWN migration even if ORM doesn't require it
|
|
452
|
+
- Test ORM-generated SQL before production (use `--dry-run` or `--preview`)
|
|
453
|
+
- Set migration timeout (ORM defaults are often too generous)
|
|
454
|
+
- Capture migration output for audit trail
|
|
455
|
+
|
|
456
|
+
### Deployment Window Coordination
|
|
457
|
+
|
|
458
|
+
```dot
|
|
459
|
+
digraph deployment_window {
|
|
460
|
+
rankdir=LR;
|
|
461
|
+
node [shape=box];
|
|
462
|
+
|
|
463
|
+
"Announce Window" -> "Run Pre-checks";
|
|
464
|
+
"Run Pre-checks" -> "Execute Migration";
|
|
465
|
+
"Execute Migration" -> "Verify Success";
|
|
466
|
+
"Verify Success" -> "Deploy App" [label="pass"];
|
|
467
|
+
"Verify Success" -> "Rollback" [label="fail"];
|
|
468
|
+
"Deploy App" -> "Close Window";
|
|
469
|
+
"Rollback" -> "Close Window";
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
**Checklist for deployment windows:**
|
|
474
|
+
- [ ] Stakeholders notified 24h in advance
|
|
475
|
+
- [ ] On-call DBA available during window
|
|
476
|
+
- [ ] Rollback script tested and ready
|
|
477
|
+
- [ ] Monitoring dashboards open
|
|
478
|
+
- [ ] Status page updated to "Maintenance"
|
|
479
|
+
|
|
480
|
+
### Environment-Specific Configuration
|
|
481
|
+
|
|
482
|
+
```yaml
|
|
483
|
+
# Example: environment-specific migration config
|
|
484
|
+
migration:
|
|
485
|
+
dev:
|
|
486
|
+
batch_size: 50000 # Faster iteration
|
|
487
|
+
pause_between: 10ms
|
|
488
|
+
timeout: 10m
|
|
489
|
+
require_rollback_test: false
|
|
490
|
+
|
|
491
|
+
staging:
|
|
492
|
+
batch_size: 10000 # Match production settings
|
|
493
|
+
pause_between: 100ms
|
|
494
|
+
timeout: 30m
|
|
495
|
+
require_rollback_test: true
|
|
496
|
+
|
|
497
|
+
production:
|
|
498
|
+
batch_size: 5000 # Conservative
|
|
499
|
+
pause_between: 200ms
|
|
500
|
+
timeout: 60m
|
|
501
|
+
require_rollback_test: true
|
|
502
|
+
require_manual_approval: true
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
## Supporting Files
|
|
506
|
+
|
|
507
|
+
These files provide detailed guidance for specific phases:
|
|
508
|
+
|
|
509
|
+
- **`expand-contract-patterns.md`** - Zero-downtime migration techniques
|
|
510
|
+
- **`large-scale-migration.md`** - Batch processing, lock minimization, progress tracking
|
|
511
|
+
- **`rollback-strategies.md`** - Rollback procedures by migration type
|
|
512
|
+
- **`validation-procedures.md`** - Pre and post-migration integrity checks
|
|
513
|
+
|
|
514
|
+
## Related Skills
|
|
515
|
+
|
|
516
|
+
- **superpowers:systematic-debugging** - For diagnosing migration failures
|
|
517
|
+
- **superpowers:incident-response** - If migration causes production incident
|
|
518
|
+
- **superpowers:test-driven-development** - For testing data transformations
|
|
519
|
+
|
|
520
|
+
## Related Agents
|
|
521
|
+
|
|
522
|
+
- **data-engineer** - For schema design and query optimization context
|
|
523
|
+
- **migration-specialist** - For legacy system modernization context
|
|
524
|
+
|
|
525
|
+
## Real-World Impact
|
|
526
|
+
|
|
527
|
+
From database migration data:
|
|
528
|
+
- Systematic migrations: 98% success rate, avg 2 hours total
|
|
529
|
+
- Ad-hoc migrations: 70% success rate, avg 8 hours (including rollbacks)
|
|
530
|
+
- Pre-tested rollback: 95% successful recovery in <15 minutes
|
|
531
|
+
- Untested rollback: 40% require restore from backup (hours of downtime)
|