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,428 @@
1
+ # Validation Procedures
2
+
3
+ Data integrity verification before and after migrations.
4
+
5
+ ## Overview
6
+
7
+ Validation is not optional. Every migration must have:
8
+ - Pre-migration validation (baseline)
9
+ - Post-migration validation (verification)
10
+ - Comparison analysis (change detection)
11
+
12
+ ## Pre-Migration Validation Checklist
13
+
14
+ ### 1. Row Count Baseline
15
+
16
+ ```sql
17
+ -- Record baseline counts
18
+ SELECT
19
+ 'users' as table_name,
20
+ COUNT(*) as total_rows,
21
+ COUNT(*) FILTER (WHERE deleted_at IS NULL) as active_rows,
22
+ NOW() as captured_at
23
+ FROM users;
24
+
25
+ -- For all affected tables
26
+ INSERT INTO migration_baselines (migration_id, table_name, metric, value)
27
+ VALUES
28
+ (:migration_id, 'users', 'total_rows', (SELECT COUNT(*) FROM users)),
29
+ (:migration_id, 'users', 'active_rows', (SELECT COUNT(*) FROM users WHERE deleted_at IS NULL));
30
+ ```
31
+
32
+ ### 2. Data Distribution
33
+
34
+ ```sql
35
+ -- Capture distribution for validation
36
+ SELECT
37
+ column_name,
38
+ COUNT(*) as count,
39
+ COUNT(*) * 100.0 / SUM(COUNT(*)) OVER () as percentage
40
+ FROM (
41
+ SELECT
42
+ CASE
43
+ WHEN status IS NULL THEN 'NULL'
44
+ ELSE status
45
+ END as column_name
46
+ FROM users
47
+ ) t
48
+ GROUP BY column_name
49
+ ORDER BY count DESC;
50
+ ```
51
+
52
+ ### 3. Referential Integrity
53
+
54
+ ```sql
55
+ -- Check foreign key integrity BEFORE migration
56
+ SELECT 'orders.user_id -> users.id' as relationship,
57
+ COUNT(*) as orphan_count
58
+ FROM orders o
59
+ LEFT JOIN users u ON o.user_id = u.id
60
+ WHERE u.id IS NULL AND o.user_id IS NOT NULL
61
+
62
+ UNION ALL
63
+
64
+ SELECT 'order_items.order_id -> orders.id',
65
+ COUNT(*)
66
+ FROM order_items oi
67
+ LEFT JOIN orders o ON oi.order_id = o.id
68
+ WHERE o.id IS NULL AND oi.order_id IS NOT NULL;
69
+ ```
70
+
71
+ ### 4. Constraint Status
72
+
73
+ ```sql
74
+ -- PostgreSQL: List all constraints
75
+ SELECT
76
+ tc.table_name,
77
+ tc.constraint_name,
78
+ tc.constraint_type,
79
+ kcu.column_name,
80
+ ccu.table_name AS references_table
81
+ FROM information_schema.table_constraints tc
82
+ JOIN information_schema.key_column_usage kcu
83
+ ON tc.constraint_name = kcu.constraint_name
84
+ LEFT JOIN information_schema.constraint_column_usage ccu
85
+ ON tc.constraint_name = ccu.constraint_name
86
+ WHERE tc.table_name = 'target_table';
87
+ ```
88
+
89
+ ### 5. Index Status
90
+
91
+ ```sql
92
+ -- PostgreSQL: Index information
93
+ SELECT
94
+ schemaname,
95
+ tablename,
96
+ indexname,
97
+ indexdef,
98
+ pg_size_pretty(pg_relation_size(indexrelid)) as index_size
99
+ FROM pg_indexes
100
+ JOIN pg_stat_user_indexes ON indexrelname = indexname
101
+ WHERE tablename = 'target_table';
102
+ ```
103
+
104
+ ## Post-Migration Validation Checklist
105
+
106
+ ### 1. Row Count Comparison
107
+
108
+ ```sql
109
+ -- Compare with baseline
110
+ SELECT
111
+ b.table_name,
112
+ b.value as baseline_count,
113
+ CASE b.table_name
114
+ WHEN 'users' THEN (SELECT COUNT(*) FROM users)
115
+ -- Add cases for other tables
116
+ END as current_count,
117
+ CASE b.table_name
118
+ WHEN 'users' THEN (SELECT COUNT(*) FROM users) - b.value
119
+ END as difference
120
+ FROM migration_baselines b
121
+ WHERE b.migration_id = :migration_id
122
+ AND b.metric = 'total_rows';
123
+ ```
124
+
125
+ ### 2. Data Transformation Verification
126
+
127
+ ```sql
128
+ -- Verify transformation applied correctly
129
+ -- Example: Email normalization migration
130
+ SELECT COUNT(*) as failed_transforms
131
+ FROM users
132
+ WHERE email_normalized IS NULL
133
+ AND email IS NOT NULL;
134
+
135
+ -- Verify transformation logic
136
+ SELECT COUNT(*) as incorrect_transforms
137
+ FROM users
138
+ WHERE email_normalized != LOWER(TRIM(email))
139
+ AND email IS NOT NULL;
140
+ ```
141
+
142
+ ### 3. NULL Value Analysis
143
+
144
+ ```sql
145
+ -- Check for unexpected NULLs after migration
146
+ SELECT
147
+ 'new_column' as column_name,
148
+ COUNT(*) FILTER (WHERE new_column IS NULL) as null_count,
149
+ COUNT(*) FILTER (WHERE new_column IS NOT NULL) as non_null_count,
150
+ ROUND(100.0 * COUNT(*) FILTER (WHERE new_column IS NULL) / COUNT(*), 2) as null_percentage
151
+ FROM users;
152
+ ```
153
+
154
+ ### 4. Referential Integrity (Post)
155
+
156
+ ```sql
157
+ -- Verify no new orphans created
158
+ SELECT 'orders.user_id' as foreign_key,
159
+ COUNT(*) as orphan_count,
160
+ CASE WHEN COUNT(*) = 0 THEN 'PASS' ELSE 'FAIL' END as status
161
+ FROM orders o
162
+ LEFT JOIN users u ON o.user_id = u.id
163
+ WHERE u.id IS NULL AND o.user_id IS NOT NULL;
164
+ ```
165
+
166
+ ### 5. Unique Constraint Verification
167
+
168
+ ```sql
169
+ -- Check for duplicate violations before adding unique constraint
170
+ SELECT column_value, COUNT(*) as duplicate_count
171
+ FROM (
172
+ SELECT new_column as column_value
173
+ FROM target_table
174
+ WHERE new_column IS NOT NULL
175
+ ) t
176
+ GROUP BY column_value
177
+ HAVING COUNT(*) > 1
178
+ ORDER BY duplicate_count DESC
179
+ LIMIT 10;
180
+ ```
181
+
182
+ ## Comparison Queries
183
+
184
+ ### Data Diff Report
185
+
186
+ ```sql
187
+ -- Generate diff report
188
+ WITH baseline AS (
189
+ SELECT * FROM users_backup_20240115
190
+ ),
191
+ current AS (
192
+ SELECT * FROM users
193
+ )
194
+ SELECT
195
+ 'added' as change_type,
196
+ c.id,
197
+ c.email
198
+ FROM current c
199
+ LEFT JOIN baseline b ON c.id = b.id
200
+ WHERE b.id IS NULL
201
+
202
+ UNION ALL
203
+
204
+ SELECT
205
+ 'removed' as change_type,
206
+ b.id,
207
+ b.email
208
+ FROM baseline b
209
+ LEFT JOIN current c ON b.id = c.id
210
+ WHERE c.id IS NULL
211
+
212
+ UNION ALL
213
+
214
+ SELECT
215
+ 'modified' as change_type,
216
+ c.id,
217
+ c.email
218
+ FROM current c
219
+ JOIN baseline b ON c.id = b.id
220
+ WHERE c.updated_at > b.updated_at;
221
+ ```
222
+
223
+ ### Column Value Comparison
224
+
225
+ ```sql
226
+ -- Compare specific column before/after
227
+ SELECT
228
+ COALESCE(b.status, 'N/A') as old_value,
229
+ COALESCE(c.status, 'N/A') as new_value,
230
+ COUNT(*) as row_count
231
+ FROM users_backup_20240115 b
232
+ FULL OUTER JOIN users c ON b.id = c.id
233
+ GROUP BY 1, 2
234
+ ORDER BY 3 DESC;
235
+ ```
236
+
237
+ ## Sampling Validation
238
+
239
+ For large tables, validate a statistical sample:
240
+
241
+ ### Random Sample Verification
242
+
243
+ ```sql
244
+ -- Validate 1% random sample
245
+ WITH sample AS (
246
+ SELECT *
247
+ FROM users
248
+ WHERE random() < 0.01
249
+ LIMIT 10000
250
+ )
251
+ SELECT
252
+ COUNT(*) as sample_size,
253
+ COUNT(*) FILTER (WHERE transformation_valid(old_col, new_col)) as valid_transforms,
254
+ COUNT(*) FILTER (WHERE NOT transformation_valid(old_col, new_col)) as invalid_transforms
255
+ FROM sample;
256
+ ```
257
+
258
+ ### Stratified Sample
259
+
260
+ ```sql
261
+ -- Sample from each partition/category
262
+ WITH stratified AS (
263
+ SELECT *,
264
+ ROW_NUMBER() OVER (PARTITION BY status ORDER BY random()) as rn
265
+ FROM users
266
+ )
267
+ SELECT
268
+ status,
269
+ COUNT(*) as sample_count,
270
+ SUM(CASE WHEN new_col IS NOT NULL THEN 1 ELSE 0 END) as migrated
271
+ FROM stratified
272
+ WHERE rn <= 100 -- 100 samples per status
273
+ GROUP BY status;
274
+ ```
275
+
276
+ ## Automated Validation Framework
277
+
278
+ ### Validation Rule Definition
279
+
280
+ ```sql
281
+ CREATE TABLE validation_rules (
282
+ rule_id SERIAL PRIMARY KEY,
283
+ migration_id VARCHAR(100),
284
+ rule_name VARCHAR(100),
285
+ rule_type VARCHAR(50), -- 'count', 'integrity', 'transform', 'custom'
286
+ table_name VARCHAR(100),
287
+ check_query TEXT,
288
+ expected_result TEXT,
289
+ severity VARCHAR(20) -- 'error', 'warning', 'info'
290
+ );
291
+
292
+ -- Example rules
293
+ INSERT INTO validation_rules (migration_id, rule_name, rule_type, table_name, check_query, expected_result, severity)
294
+ VALUES
295
+ ('mig_001', 'row_count_preserved', 'count', 'users',
296
+ 'SELECT COUNT(*) FROM users',
297
+ '${baseline_count}', 'error'),
298
+
299
+ ('mig_001', 'no_orphan_orders', 'integrity', 'orders',
300
+ 'SELECT COUNT(*) FROM orders o LEFT JOIN users u ON o.user_id = u.id WHERE u.id IS NULL',
301
+ '0', 'error'),
302
+
303
+ ('mig_001', 'transform_complete', 'transform', 'users',
304
+ 'SELECT COUNT(*) FROM users WHERE new_col IS NULL AND old_col IS NOT NULL',
305
+ '0', 'error');
306
+ ```
307
+
308
+ ### Validation Runner
309
+
310
+ ```sql
311
+ -- Run all validations for a migration
312
+ WITH validation_results AS (
313
+ SELECT
314
+ r.rule_id,
315
+ r.rule_name,
316
+ r.severity,
317
+ r.expected_result,
318
+ -- Dynamic execution would need procedural code
319
+ 'placeholder' as actual_result
320
+ FROM validation_rules r
321
+ WHERE r.migration_id = :migration_id
322
+ )
323
+ SELECT
324
+ rule_name,
325
+ severity,
326
+ expected_result,
327
+ actual_result,
328
+ CASE WHEN expected_result = actual_result THEN 'PASS' ELSE 'FAIL' END as status
329
+ FROM validation_results
330
+ ORDER BY
331
+ CASE severity WHEN 'error' THEN 1 WHEN 'warning' THEN 2 ELSE 3 END,
332
+ rule_name;
333
+ ```
334
+
335
+ ## Continuous Validation
336
+
337
+ For long-running migrations, validate continuously:
338
+
339
+ ### Progress Validation
340
+
341
+ ```sql
342
+ -- Check every N batches
343
+ SELECT
344
+ (SELECT COUNT(*) FROM users WHERE new_col IS NOT NULL) as migrated,
345
+ (SELECT COUNT(*) FROM users) as total,
346
+ (SELECT COUNT(*) FROM users WHERE new_col IS NULL AND old_col IS NOT NULL) as pending,
347
+ (SELECT COUNT(*) FROM users WHERE new_col != expected_transform(old_col)) as errors
348
+ FROM dual;
349
+ ```
350
+
351
+ ### Error Log Table
352
+
353
+ ```sql
354
+ CREATE TABLE migration_errors (
355
+ error_id SERIAL PRIMARY KEY,
356
+ migration_id VARCHAR(100),
357
+ row_id BIGINT,
358
+ error_type VARCHAR(50),
359
+ error_message TEXT,
360
+ old_value TEXT,
361
+ attempted_value TEXT,
362
+ created_at TIMESTAMP DEFAULT NOW()
363
+ );
364
+
365
+ -- Log errors during migration
366
+ INSERT INTO migration_errors (migration_id, row_id, error_type, error_message, old_value, attempted_value)
367
+ SELECT
368
+ :migration_id,
369
+ id,
370
+ 'transform_error',
371
+ 'Value truncation required',
372
+ old_col,
373
+ LEFT(old_col, 50)
374
+ FROM users
375
+ WHERE LENGTH(old_col) > 50;
376
+ ```
377
+
378
+ ## Validation Report Template
379
+
380
+ ### Summary Section
381
+
382
+ ```
383
+ Migration Validation Report
384
+ ===========================
385
+ Migration ID: mig_001
386
+ Executed At: 2024-01-15 14:30:00
387
+ Duration: 2 hours 15 minutes
388
+
389
+ Overall Status: PASS/FAIL
390
+
391
+ Tables Affected: 3
392
+ Rows Processed: 1,500,000
393
+ Errors Encountered: 0
394
+ ```
395
+
396
+ ### Detail Sections
397
+
398
+ ```
399
+ Row Count Validation
400
+ --------------------
401
+ | Table | Baseline | Current | Diff | Status |
402
+ |---------|-----------|-----------|-------|--------|
403
+ | users | 1,000,000 | 1,000,000 | 0 | PASS |
404
+ | orders | 500,000 | 500,000 | 0 | PASS |
405
+
406
+ Transformation Validation
407
+ -------------------------
408
+ | Column | Expected | Actual | Status |
409
+ |-----------------|----------|--------|--------|
410
+ | email_normalized| 1,000,000| 1,000,000| PASS |
411
+
412
+ Integrity Validation
413
+ --------------------
414
+ | Relationship | Orphans | Status |
415
+ |-------------------------|---------|--------|
416
+ | orders.user_id -> users | 0 | PASS |
417
+ ```
418
+
419
+ ## Common Validation Mistakes
420
+
421
+ | Mistake | Consequence | Prevention |
422
+ |---------|-------------|------------|
423
+ | Skip pre-migration baseline | No comparison possible | Always capture baseline first |
424
+ | Sample too small | Miss edge cases | Use statistically significant sample |
425
+ | Only validate success | Miss silent failures | Also validate expected counts |
426
+ | Ignore warnings | Issues become errors later | Address all warnings |
427
+ | Validate once | Miss delayed issues | Continuous validation for large migrations |
428
+ | Trust row counts only | Data corruption undetected | Validate data content too |