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.
Files changed (53) hide show
  1. package/.ai-rules/CHANGELOG.md +122 -0
  2. package/.ai-rules/agents/README.md +527 -11
  3. package/.ai-rules/agents/accessibility-specialist.json +0 -1
  4. package/.ai-rules/agents/act-mode.json +0 -1
  5. package/.ai-rules/agents/agent-architect.json +0 -1
  6. package/.ai-rules/agents/ai-ml-engineer.json +0 -1
  7. package/.ai-rules/agents/architecture-specialist.json +14 -2
  8. package/.ai-rules/agents/backend-developer.json +14 -2
  9. package/.ai-rules/agents/code-quality-specialist.json +0 -1
  10. package/.ai-rules/agents/data-engineer.json +0 -1
  11. package/.ai-rules/agents/devops-engineer.json +24 -2
  12. package/.ai-rules/agents/documentation-specialist.json +0 -1
  13. package/.ai-rules/agents/eval-mode.json +0 -1
  14. package/.ai-rules/agents/event-architecture-specialist.json +719 -0
  15. package/.ai-rules/agents/frontend-developer.json +14 -2
  16. package/.ai-rules/agents/i18n-specialist.json +0 -1
  17. package/.ai-rules/agents/integration-specialist.json +11 -1
  18. package/.ai-rules/agents/migration-specialist.json +676 -0
  19. package/.ai-rules/agents/mobile-developer.json +0 -1
  20. package/.ai-rules/agents/observability-specialist.json +747 -0
  21. package/.ai-rules/agents/performance-specialist.json +24 -2
  22. package/.ai-rules/agents/plan-mode.json +0 -1
  23. package/.ai-rules/agents/platform-engineer.json +0 -1
  24. package/.ai-rules/agents/security-specialist.json +27 -16
  25. package/.ai-rules/agents/seo-specialist.json +0 -1
  26. package/.ai-rules/agents/solution-architect.json +0 -1
  27. package/.ai-rules/agents/technical-planner.json +0 -1
  28. package/.ai-rules/agents/test-strategy-specialist.json +14 -2
  29. package/.ai-rules/agents/ui-ux-designer.json +0 -1
  30. package/.ai-rules/rules/core.md +25 -0
  31. package/.ai-rules/skills/README.md +35 -0
  32. package/.ai-rules/skills/database-migration/SKILL.md +531 -0
  33. package/.ai-rules/skills/database-migration/expand-contract-patterns.md +314 -0
  34. package/.ai-rules/skills/database-migration/large-scale-migration.md +414 -0
  35. package/.ai-rules/skills/database-migration/rollback-strategies.md +359 -0
  36. package/.ai-rules/skills/database-migration/validation-procedures.md +428 -0
  37. package/.ai-rules/skills/dependency-management/SKILL.md +381 -0
  38. package/.ai-rules/skills/dependency-management/license-compliance.md +282 -0
  39. package/.ai-rules/skills/dependency-management/lock-file-management.md +437 -0
  40. package/.ai-rules/skills/dependency-management/major-upgrade-guide.md +292 -0
  41. package/.ai-rules/skills/dependency-management/security-vulnerability-response.md +230 -0
  42. package/.ai-rules/skills/incident-response/SKILL.md +373 -0
  43. package/.ai-rules/skills/incident-response/communication-templates.md +322 -0
  44. package/.ai-rules/skills/incident-response/escalation-matrix.md +347 -0
  45. package/.ai-rules/skills/incident-response/postmortem-template.md +351 -0
  46. package/.ai-rules/skills/incident-response/severity-classification.md +256 -0
  47. package/.ai-rules/skills/performance-optimization/CREATION-LOG.md +87 -0
  48. package/.ai-rules/skills/performance-optimization/SKILL.md +76 -0
  49. package/.ai-rules/skills/performance-optimization/documentation-template.md +70 -0
  50. package/.ai-rules/skills/pr-review/SKILL.md +768 -0
  51. package/.ai-rules/skills/refactoring/SKILL.md +192 -0
  52. package/.ai-rules/skills/refactoring/refactoring-catalog.md +1377 -0
  53. package/package.json +1 -1
@@ -0,0 +1,359 @@
1
+ # Rollback Strategies
2
+
3
+ Comprehensive rollback procedures by migration type.
4
+
5
+ ## The Golden Rule
6
+
7
+ ```
8
+ EVERY MIGRATION MUST HAVE A TESTED ROLLBACK BEFORE EXECUTION
9
+ ```
10
+
11
+ - Test rollback in staging with production-like data
12
+ - Measure rollback duration
13
+ - Verify data integrity after rollback
14
+ - Document the exact rollback commands
15
+
16
+ ## Rollback Decision Matrix
17
+
18
+ | Migration Type | Rollback Complexity | Data Loss Risk | Recommended Strategy |
19
+ |----------------|--------------------|-----------------|--------------------|
20
+ | ADD COLUMN (nullable) | Simple | None | DROP COLUMN |
21
+ | ADD COLUMN (NOT NULL) | Medium | Possible | Dual-write + restore |
22
+ | DROP COLUMN | Complex | **Certain** | Restore from backup |
23
+ | RENAME COLUMN | Medium | None | Reverse rename |
24
+ | CHANGE TYPE (widen) | Simple | None | No action needed |
25
+ | CHANGE TYPE (narrow) | Complex | **Possible** | Restore from backup |
26
+ | ADD INDEX | Simple | None | DROP INDEX |
27
+ | ADD FK | Simple | None | DROP FK |
28
+ | DROP FK | Medium | None | Re-add FK |
29
+ | SPLIT TABLE | Complex | None | Reverse merge |
30
+ | MERGE TABLES | Complex | None | Reverse split |
31
+
32
+ ## Strategy 1: Instant Rollback (DDL-Only)
33
+
34
+ **Use for:** Schema changes that can be reversed with DDL
35
+
36
+ ### ADD COLUMN Rollback
37
+ ```sql
38
+ -- Forward
39
+ ALTER TABLE users ADD COLUMN status VARCHAR(20);
40
+
41
+ -- Rollback (instant)
42
+ ALTER TABLE users DROP COLUMN status;
43
+ ```
44
+
45
+ ### ADD INDEX Rollback
46
+ ```sql
47
+ -- Forward
48
+ CREATE INDEX idx_users_email ON users(email);
49
+
50
+ -- Rollback (instant)
51
+ DROP INDEX idx_users_email;
52
+ ```
53
+
54
+ ### ADD CONSTRAINT Rollback
55
+ ```sql
56
+ -- Forward
57
+ ALTER TABLE orders
58
+ ADD CONSTRAINT chk_positive_amount CHECK (amount > 0);
59
+
60
+ -- Rollback (instant)
61
+ ALTER TABLE orders DROP CONSTRAINT chk_positive_amount;
62
+ ```
63
+
64
+ ## Strategy 2: Data Preservation Rollback
65
+
66
+ **Use for:** Changes that modify data but preserve original
67
+
68
+ ### NOT NULL with Default
69
+
70
+ ```sql
71
+ -- Forward
72
+ ALTER TABLE users
73
+ ALTER COLUMN status SET DEFAULT 'active',
74
+ ALTER COLUMN status SET NOT NULL;
75
+
76
+ -- Rollback
77
+ ALTER TABLE users
78
+ ALTER COLUMN status DROP NOT NULL,
79
+ ALTER COLUMN status DROP DEFAULT;
80
+
81
+ -- Note: Data modified (NULLs became 'active')
82
+ -- May need: UPDATE users SET status = NULL WHERE status = 'active' AND original_was_null;
83
+ ```
84
+
85
+ ### Best Practice: Dual-Write Pattern
86
+
87
+ ```sql
88
+ -- Before migration: add tracking column
89
+ ALTER TABLE users ADD COLUMN status_was_null BOOLEAN;
90
+
91
+ -- Forward migration
92
+ UPDATE users SET status_was_null = (status IS NULL) WHERE status_was_null IS NULL;
93
+ UPDATE users SET status = 'active' WHERE status IS NULL;
94
+ ALTER TABLE users ALTER COLUMN status SET NOT NULL;
95
+
96
+ -- Rollback with data preservation
97
+ ALTER TABLE users ALTER COLUMN status DROP NOT NULL;
98
+ UPDATE users SET status = NULL WHERE status_was_null = true;
99
+ ALTER TABLE users DROP COLUMN status_was_null;
100
+ ```
101
+
102
+ ## Strategy 3: Backup-Based Rollback
103
+
104
+ **Use for:** Destructive changes (DROP, TYPE narrowing)
105
+
106
+ ### Pre-Migration Backup
107
+
108
+ ```sql
109
+ -- Create backup before destructive change
110
+ CREATE TABLE users_backup_20240115 AS SELECT * FROM users;
111
+
112
+ -- Forward (destructive)
113
+ ALTER TABLE users DROP COLUMN legacy_data;
114
+
115
+ -- Rollback from backup
116
+ ALTER TABLE users ADD COLUMN legacy_data TEXT;
117
+
118
+ UPDATE users u
119
+ SET legacy_data = b.legacy_data
120
+ FROM users_backup_20240115 b
121
+ WHERE u.id = b.id;
122
+
123
+ -- Cleanup after confirmed rollback
124
+ DROP TABLE users_backup_20240115;
125
+ ```
126
+
127
+ ### Point-in-Time Recovery (PITR)
128
+
129
+ ```sql
130
+ -- PostgreSQL: Recover to specific time
131
+ -- (Requires proper WAL archiving configuration)
132
+ SELECT pg_create_restore_point('before_migration_xyz');
133
+
134
+ -- After migration failure, restore to this point
135
+ -- This is a DBA operation, not a SQL command
136
+ ```
137
+
138
+ ## Strategy 4: Shadow Table Rollback
139
+
140
+ **Use for:** Complex transformations, column renames
141
+
142
+ ### Forward Migration
143
+
144
+ ```sql
145
+ -- Create shadow
146
+ ALTER TABLE products ADD COLUMN name_v2 VARCHAR(255);
147
+
148
+ -- Sync trigger
149
+ CREATE TRIGGER sync_name
150
+ BEFORE INSERT OR UPDATE ON products
151
+ FOR EACH ROW
152
+ EXECUTE FUNCTION sync_columns('name', 'name_v2');
153
+
154
+ -- Backfill
155
+ UPDATE products SET name_v2 = name WHERE name_v2 IS NULL;
156
+
157
+ -- Application switches to name_v2
158
+ -- ... time passes, monitoring shows success ...
159
+
160
+ -- Contract (danger zone)
161
+ DROP TRIGGER sync_name ON products;
162
+ ALTER TABLE products DROP COLUMN name;
163
+ ALTER TABLE products RENAME COLUMN name_v2 TO name;
164
+ ```
165
+
166
+ ### Rollback at Each Phase
167
+
168
+ **Phase: Shadow exists**
169
+ ```sql
170
+ -- Simple: just drop shadow
171
+ DROP TRIGGER sync_name ON products;
172
+ ALTER TABLE products DROP COLUMN name_v2;
173
+ ```
174
+
175
+ **Phase: Application using shadow**
176
+ ```sql
177
+ -- Revert application to old column
178
+ -- Drop shadow
179
+ DROP TRIGGER sync_name ON products;
180
+ ALTER TABLE products DROP COLUMN name_v2;
181
+ ```
182
+
183
+ **Phase: After contract (original dropped)**
184
+ ```sql
185
+ -- Complex: restore from backup
186
+ ALTER TABLE products ADD COLUMN name VARCHAR(255);
187
+
188
+ UPDATE products p
189
+ SET name = b.name
190
+ FROM products_backup_20240115 b
191
+ WHERE p.id = b.id;
192
+ ```
193
+
194
+ ## Strategy 5: Blue-Green Database Rollback
195
+
196
+ **Use for:** Major schema overhauls, critical systems
197
+
198
+ ### Setup
199
+
200
+ ```
201
+ DB-Blue: Current production schema
202
+ DB-Green: New schema (clone of Blue + migrations)
203
+ ```
204
+
205
+ ### Rollback Process
206
+
207
+ ```
208
+ 1. Issue detected with Green
209
+ 2. Stop writes to Green
210
+ 3. Switch application back to Blue (DNS/config)
211
+ 4. Resume operations on Blue
212
+ 5. Debug Green offline
213
+ ```
214
+
215
+ ### Data Sync Consideration
216
+
217
+ ```sql
218
+ -- If data written to Green needs preservation:
219
+ -- Export Green-only data
220
+ SELECT * FROM green_db.orders
221
+ WHERE created_at > :cutover_time
222
+ INTO OUTFILE '/tmp/green_orders.csv';
223
+
224
+ -- Import to Blue
225
+ LOAD DATA INFILE '/tmp/green_orders.csv'
226
+ INTO TABLE blue_db.orders;
227
+ ```
228
+
229
+ ## Rollback Testing Checklist
230
+
231
+ | Test | Purpose | Pass Criteria |
232
+ |------|---------|---------------|
233
+ | Execute rollback | Verify commands work | No errors |
234
+ | Data integrity | Verify no data loss | Row counts match |
235
+ | Application health | Verify app works after rollback | All smoke tests pass |
236
+ | Performance | Verify acceptable speed | Query times unchanged |
237
+ | Constraint validity | Verify FK/CHECK constraints | No violations |
238
+ | Index integrity | Verify indexes valid | EXPLAIN plans correct |
239
+
240
+ ## Rollback Time Estimates
241
+
242
+ | Operation | Table Size | Estimated Time |
243
+ |-----------|------------|----------------|
244
+ | DROP COLUMN | Any | Instant |
245
+ | DROP INDEX | Any | Instant |
246
+ | DROP CONSTRAINT | Any | Instant |
247
+ | ADD COLUMN | Any | Instant |
248
+ | Restore from backup | 1M rows | 5-15 min |
249
+ | Restore from backup | 10M rows | 30-60 min |
250
+ | Restore from backup | 100M rows | 4-8 hours |
251
+ | PITR | Depends on WAL | 15-60 min |
252
+
253
+ ## Automated Rollback Script Template
254
+
255
+ ```bash
256
+ #!/bin/bash
257
+ # rollback-migration-xyz.sh
258
+
259
+ set -e # Exit on error
260
+
261
+ MIGRATION_NAME="xyz"
262
+ BACKUP_TABLE="users_backup_${MIGRATION_NAME}"
263
+ ROLLBACK_LOG="/var/log/migrations/rollback_${MIGRATION_NAME}.log"
264
+
265
+ echo "Starting rollback for migration: ${MIGRATION_NAME}" | tee -a $ROLLBACK_LOG
266
+ echo "Timestamp: $(date -Iseconds)" | tee -a $ROLLBACK_LOG
267
+
268
+ # Step 1: Verify backup exists
269
+ echo "Checking backup table..." | tee -a $ROLLBACK_LOG
270
+ psql -c "SELECT COUNT(*) FROM ${BACKUP_TABLE}" || {
271
+ echo "ERROR: Backup table not found!" | tee -a $ROLLBACK_LOG
272
+ exit 1
273
+ }
274
+
275
+ # Step 2: Execute rollback
276
+ echo "Executing rollback DDL..." | tee -a $ROLLBACK_LOG
277
+ psql -f /migrations/${MIGRATION_NAME}/rollback.sql 2>&1 | tee -a $ROLLBACK_LOG
278
+
279
+ # Step 3: Restore data if needed
280
+ echo "Restoring data from backup..." | tee -a $ROLLBACK_LOG
281
+ psql -c "
282
+ UPDATE users u
283
+ SET dropped_column = b.dropped_column
284
+ FROM ${BACKUP_TABLE} b
285
+ WHERE u.id = b.id;
286
+ " 2>&1 | tee -a $ROLLBACK_LOG
287
+
288
+ # Step 4: Verify rollback
289
+ echo "Verifying rollback..." | tee -a $ROLLBACK_LOG
290
+ VERIFICATION=$(psql -t -c "
291
+ SELECT COUNT(*) FROM users
292
+ WHERE dropped_column IS NULL
293
+ AND id IN (SELECT id FROM ${BACKUP_TABLE} WHERE dropped_column IS NOT NULL);
294
+ ")
295
+
296
+ if [ "$VERIFICATION" != "0" ]; then
297
+ echo "ERROR: Rollback verification failed! ${VERIFICATION} rows missing data." | tee -a $ROLLBACK_LOG
298
+ exit 1
299
+ fi
300
+
301
+ echo "Rollback completed successfully!" | tee -a $ROLLBACK_LOG
302
+ ```
303
+
304
+ ## Emergency Rollback Procedure
305
+
306
+ **When things go wrong in production:**
307
+
308
+ ### Step 1: STOP (30 seconds)
309
+ ```
310
+ - Stop the migration if still running
311
+ - Assess the damage (what failed, what's affected)
312
+ - Do NOT attempt ad-hoc fixes
313
+ ```
314
+
315
+ ### Step 2: COMMUNICATE (1 minute)
316
+ ```
317
+ - Post in incident channel
318
+ - Alert on-call DBA
319
+ - Update status page if user-facing
320
+ ```
321
+
322
+ ### Step 3: ASSESS (2-5 minutes)
323
+ ```
324
+ - Check application errors
325
+ - Check replication status
326
+ - Identify rollback strategy needed
327
+ ```
328
+
329
+ ### Step 4: EXECUTE (varies)
330
+ ```
331
+ - Use pre-tested rollback script
332
+ - Monitor progress
333
+ - Verify each step
334
+ ```
335
+
336
+ ### Step 5: VERIFY (5-10 minutes)
337
+ ```
338
+ - Run validation queries
339
+ - Check application health
340
+ - Confirm service restored
341
+ ```
342
+
343
+ ### Step 6: DOCUMENT
344
+ ```
345
+ - Record what happened
346
+ - Schedule postmortem
347
+ - Update rollback procedures if needed
348
+ ```
349
+
350
+ ## Common Rollback Mistakes
351
+
352
+ | Mistake | Consequence | Prevention |
353
+ |---------|-------------|------------|
354
+ | No backup before DROP | Permanent data loss | Always backup before destructive ops |
355
+ | Untested rollback script | Script fails in production | Test every rollback in staging |
356
+ | Forgot trigger removal | Dual-write continues | Include trigger cleanup in rollback |
357
+ | Rollback during peak | Extended impact | Schedule rollbacks for low-traffic |
358
+ | Partial rollback | Inconsistent state | Rollback fully or not at all |
359
+ | Skip verification | Silent failures | Always run post-rollback validation |