ai-developer-skill-os 9.1.1 → 9.3.0

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 (63) hide show
  1. package/.agents/AGENTS.md +139 -42
  2. package/.agents/DEV_PROFILE.md +95 -0
  3. package/.agents/registry/capability-graph.yml +171 -334
  4. package/.agents/registry/graph.json +52 -18
  5. package/.agents/registry/index.yaml +66 -12
  6. package/.agents/registry/skills-index.yml +204 -447
  7. package/.agents/rules/coding.md +23 -0
  8. package/.agents/rules/global.md +44 -30
  9. package/.agents/skills/_template/SKILL.md +2 -300
  10. package/.agents/skills/qk-access-policy/SKILL.md +98 -393
  11. package/.agents/skills/qk-agent-observability/SKILL.md +3 -359
  12. package/.agents/skills/qk-ai-builder/SKILL.md +132 -485
  13. package/.agents/skills/qk-api-consumer/SKILL.md +256 -0
  14. package/.agents/skills/qk-api-consumer/capability.yaml +21 -0
  15. package/.agents/skills/qk-api-consumer/evals/scorecard.yaml +29 -0
  16. package/.agents/skills/qk-api-lifecycle/SKILL.md +133 -376
  17. package/.agents/skills/qk-bug-resolution/SKILL.md +128 -481
  18. package/.agents/skills/qk-code-review/SKILL.md +142 -340
  19. package/.agents/skills/qk-context-loader/SKILL.md +99 -391
  20. package/.agents/skills/qk-data-engineer/SKILL.md +253 -0
  21. package/.agents/skills/qk-data-lifecycle/SKILL.md +89 -408
  22. package/.agents/skills/qk-db-optimizer/SKILL.md +102 -408
  23. package/.agents/skills/qk-design-system-engineering/SKILL.md +76 -381
  24. package/.agents/skills/qk-devops-platform/SKILL.md +77 -383
  25. package/.agents/skills/qk-docs/SKILL.md +88 -414
  26. package/.agents/skills/qk-engineering-standard/SKILL.md +4 -508
  27. package/.agents/skills/qk-fe-api-integration/SKILL.md +343 -263
  28. package/.agents/skills/qk-fe-api-integration/evals/scorecard.yaml +29 -29
  29. package/.agents/skills/qk-feature-delivery/SKILL.md +137 -365
  30. package/.agents/skills/qk-feature-delivery/evals/scorecard.yaml +1 -1
  31. package/.agents/skills/qk-frontend-architecture/SKILL.md +5 -399
  32. package/.agents/skills/qk-help/evals/scorecard.yaml +13 -13
  33. package/.agents/skills/qk-orchestrator/SKILL.md +63 -422
  34. package/.agents/skills/qk-orchestrator/references/routing-table.md +10 -14
  35. package/.agents/skills/qk-product-specification/SKILL.md +70 -399
  36. package/.agents/skills/qk-production-release/SKILL.md +80 -457
  37. package/.agents/skills/qk-project-audit/SKILL.md +174 -0
  38. package/.agents/skills/qk-project-bootstrap/SKILL.md +244 -392
  39. package/.agents/skills/qk-project-health/SKILL.md +97 -416
  40. package/.agents/skills/qk-project-memory/SKILL.md +76 -21
  41. package/.agents/skills/qk-refactor/SKILL.md +167 -304
  42. package/.agents/skills/qk-security-audit/SKILL.md +141 -383
  43. package/.agents/skills/qk-security-audit/capability.yaml +1 -2
  44. package/.agents/skills/qk-system-evolution/SKILL.md +343 -263
  45. package/.agents/skills/qk-system-evolution/evals/scorecard.yaml +26 -26
  46. package/.agents/skills/qk-test-engineering/SKILL.md +119 -429
  47. package/.agents/skills/qk-ui-audit/SKILL.md +73 -457
  48. package/.agents/skills/qk-ui-builder/SKILL.md +521 -482
  49. package/.agents/skills/qk-ui-system-builder/SKILL.md +68 -434
  50. package/.agents/skills/qk-upgrade/SKILL.md +301 -0
  51. package/.agents/skills/qk-upgrade/capability.yaml +24 -0
  52. package/.agents/skills/qk-upgrade/evals/scorecard.yaml +26 -0
  53. package/.agents/skills/qk-validation-gate/SKILL.md +4 -523
  54. package/.agents/skills/qk-web-quality-gate/SKILL.md +85 -383
  55. package/.agents/workflows/bug-resolution.yml +6 -6
  56. package/.agents/workflows/context-discovery.yml +94 -0
  57. package/.agents/workflows/feature-delivery.yml +8 -4
  58. package/.agents/workflows/refactor.yml +6 -3
  59. package/.agents/workflows/shared/quality-gate.yml +94 -0
  60. package/.agents/workflows/skin-governance.yml +115 -0
  61. package/README.md +152 -67
  62. package/package.json +2 -2
  63. package/tooling/build-registry.js +30 -8
@@ -1,9 +1,9 @@
1
- ---
1
+ ---
2
2
  # ── Identity ───────────────────────────────────────────────
3
3
  name: qk-data-lifecycle
4
- version: 9.1.0
4
+ version: 9.2.0
5
5
  status: stable
6
- description: "Quản lý Schema, Migrations an toàn — schema freeze → backward-compat migration → cleanup."
6
+ description: "Quản lý Schema và Migration cơ sở dữ liệu an toàn — schema freeze, backward-compatible migrations, data transformation, zero-downtime deployment. Dùng skill này khi user nhắc đến: sửa schema, migration, database model, db schema, cập nhật database, đổi model, thêm cột, alter table — kể cả khi chỉ nói 'thêm trường phone vào bảng users'."
7
7
  platforms: [antigravity, claude-code, cursor, windsurf, kilo-code]
8
8
 
9
9
  # ── V9: Classification ─────────────────────────────────────
@@ -21,11 +21,16 @@ complexity:
21
21
  has_external_dependency: true
22
22
  has_breaking_change: false
23
23
 
24
- triggers:
25
- - "sửa schema"
26
- - "cập nhật database"
27
- - "tạo migration"
28
- - "đổi model"
24
+ triggers:
25
+ - "sửa schema"
26
+ - "migration"
27
+ - "database model"
28
+ - "db schema"
29
+ - "cập nhật database"
30
+ - "đổi model"
31
+ - "thêm cột"
32
+ - "alter table"
33
+
29
34
 
30
35
  # ── V8: References ─────────────────────────────────────────
31
36
  workflow: feature-delivery
@@ -33,6 +38,7 @@ workflow: feature-delivery
33
38
  rules:
34
39
  - global
35
40
  - coding
41
+ - safety
36
42
 
37
43
  tools:
38
44
  - filesystem
@@ -40,11 +46,13 @@ tools:
40
46
 
41
47
  related_skills:
42
48
  - qk-db-optimizer
49
+ - qk-api-lifecycle
43
50
 
44
51
  knowledge_scope:
45
52
  owns:
46
53
  - schema
47
54
  - migrations
55
+ - data-contracts
48
56
  references:
49
57
  - architecture
50
58
  - security
@@ -72,445 +80,118 @@ produces: [code, schema]
72
80
  consumes: [context-graph, user-description]
73
81
 
74
82
  token_budget:
75
- max_files_read: 4
76
- max_lines_per_read: 100
77
- max_shell_commands: 1
83
+ max_files_read: 5
84
+ max_lines_per_read: 150
85
+ max_shell_commands: 2
78
86
  stop_early: true
79
87
 
80
- exit_codes: [SUCCESS, BLOCKED, FAILED, PARTIAL]
88
+ exit_codes: [SUCCESS, BLOCKED, FAILED, PARTIAL]
81
89
  ---
82
90
 
83
- # qk-data-lifecycle — Database Schema & Repository Manager
91
+ # qk-data-lifecycle — Database Schema & Migration Guardian
84
92
 
85
93
  > **Language rule:** Code, identifiers, file names → English. Explanations, summaries → Vietnamese.
86
94
 
95
+ Chịu trách nhiệm quản lý vòng đời Schema DB và Migration an toàn theo nguyên tắc: **Freeze schema → Backward-compatible migration (Expand & Contract) → Cleanup**. Tuyệt đối không làm đứt gãy runtime hoặc gây mất mát dữ liệu live.
96
+
87
97
  ---
88
98
 
89
- ## Memory Workflow
90
-
91
- ### 0. Self-Init Protocol (Khởi Tạo Bộ Nhớ Local & Gitignore)
92
- - Trước khi tra cứu hoặc lưu trữ tri thức, BẮT BUỘC kiểm tra sự tồn tại của thư mục `.ai-local/` tại gốc dự án:
93
- - **Tự động tạo mới:** Nếu `.ai-local/` chưa tồn tại, AI phải tự động tạo cấu trúc thư mục `.ai-local/knowledge/` (và file `index.yaml` nếu cần thiết) cùng `.ai-local/candidates/`. Tuyệt đối không ngưng chạy hay hỏi ý kiến người dùng về thao tác khởi tạo tiêu chuẩn này.
94
- - **Bảo mật Gitignore:** BẮT BUỘC kiểm tra file `.gitignore` của dự án, nếu chưa có dòng `.ai-local/` thì phải tự động thêm vào để tuyệt đối bảo mật tri thức cá nhân và tránh lộ lọt lên Git.
95
-
96
- ---
97
-
98
- ### Pre-flight Retrieve (Trước khi thực thi)
99
- - Trước các task có tính lặp lại, debug, refactor, kiến trúc hoặc rủi ro cao:
100
- bắt buộc tra cứu:
101
- - `.ai-local/knowledge/index.yaml` (Private Local Knowledge)
102
-
103
- - Ưu tiên sử dụng các Knowledge đang có trạng thái `Active` thuộc:
104
- - Architecture
105
- - Hard Bug
106
- - Convention
107
- - Pattern
108
- - Tech Debt Pattern
109
- - 👉 *Domain Focus:* Convention / Architecture (vd: chiến lược migration backward-compatible, quy định FK).
110
-
111
- - Memory chỉ đóng vai trò **Navigator (bản đồ chỉ đường)**.
112
- Không được xem Memory là Source of Truth.
113
- Luôn xác minh lại bằng source code, configuration và trạng thái hiện tại của dự án trước khi áp dụng.
114
-
115
- ---
116
-
117
- ### Learning Flow (AI tự học có kiểm soát)
118
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
119
- - Hard Bug có khả năng tái diễn.
120
- - Pattern làm việc lặp lại trong dự án.
121
- - Convention hoặc quy tắc kiến trúc mới.
122
- - Quyết định Architecture quan trọng.
123
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
124
- - 👉 *Domain Harvest:* Quyết định Architecture quan trọng (vd: chuẩn index CSDL, quy tắc phân trang mới).
125
-
126
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
127
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
128
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
129
-
130
- ---
131
-
132
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
133
- Sau khi hoàn thành task:
134
- - AI đánh giá các Candidate Memory đã tạo.
135
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
136
- - Đề xuất người dùng xem xét.
137
- - Gửi yêu cầu phê duyệt thông qua:
138
- - `/learn`
139
- - `qk-project-memory`
140
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
141
-
142
- ```
143
- .ai-local/candidates/ ──(Approve)──> .ai-local/knowledge/index.yaml
144
- ```
145
-
146
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
147
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
148
-
149
- ---
150
-
151
- ### Ignore (Không đưa vào Memory)
152
- Không lưu:
153
- - Trace log của một session đơn lẻ.
154
- - Temporary debugging data.
155
- - Output của một lần chạy test/scan.
156
- - Report health tạm thời của một đợt kiểm tra.
157
- - Lỗi nhỏ chỉ xảy ra một lần.
158
- - Thông tin không có khả năng tái sử dụng.
159
- - 👉 *Domain Ignore:* Thao tác thêm trường đơn giản hoặc temporary database fix.
160
-
161
- ---
162
-
163
- ### Golden Rule
164
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
165
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
166
-
167
- ---
168
-
169
-
170
-
171
- ### Pre-flight Retrieve (Trước khi thực thi)
172
- - Trước các task có tính lặp lại, debug, refactor, kiến trúc hoặc rủi ro cao:
173
- bắt buộc tra cứu:
174
- - `.agents/knowledge/index.yaml` (Shared Project Knowledge)
175
- - `.ai-local/knowledge/index.yaml` (Private Local Knowledge)
176
-
177
- - Ưu tiên sử dụng các Knowledge đang có trạng thái `Active` thuộc:
178
- - Architecture
179
- - Hard Bug
180
- - Convention
181
- - Pattern
182
- - Tech Debt Pattern
183
- - 👉 *Domain Focus:* Convention / Architecture (vd: chiến lược migration backward-compatible, quy định FK).
184
-
185
- - Memory chỉ đóng vai trò **Navigator (bản đồ chỉ đường)**.
186
- Không được xem Memory là Source of Truth.
187
- Luôn xác minh lại bằng source code, configuration và trạng thái hiện tại của dự án trước khi áp dụng.
188
-
189
- ---
190
-
191
- ### Learning Flow (AI tự học có kiểm soát)
192
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
193
- - Hard Bug có khả năng tái diễn.
194
- - Pattern làm việc lặp lại trong dự án.
195
- - Convention hoặc quy tắc kiến trúc mới.
196
- - Quyết định Architecture quan trọng.
197
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
198
- - 👉 *Domain Harvest:* Quyết định Architecture quan trọng (vd: chuẩn index CSDL, quy tắc phân trang mới).
199
-
200
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
201
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
202
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
203
-
204
- ---
205
-
206
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
207
- Sau khi hoàn thành task:
208
- - AI đánh giá các Candidate Memory đã tạo.
209
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
210
- - Đề xuất người dùng xem xét.
211
- - Gửi yêu cầu phê duyệt thông qua:
212
- - `/learn`
213
- - `qk-project-memory`
214
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
215
-
216
- ```
217
- .ai-local/candidates/ ──(Approve)──> .agents/knowledge/index.yaml
218
- ```
219
-
220
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
221
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
222
-
223
- ---
224
-
225
- ### Ignore (Không đưa vào Memory)
226
- Không lưu:
227
- - Trace log của một session đơn lẻ.
228
- - Temporary debugging data.
229
- - Output của một lần chạy test/scan.
230
- - Report health tạm thời của một đợt kiểm tra.
231
- - Lỗi nhỏ chỉ xảy ra một lần.
232
- - Thông tin không có khả năng tái sử dụng.
233
- - 👉 *Domain Ignore:* Thao tác thêm trường đơn giản hoặc temporary database fix.
234
-
235
- ---
236
-
237
- ### Golden Rule
238
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
239
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
240
-
241
- ---
242
- ---
243
-
244
- ### Learning Flow (AI tự học có kiểm soát)
245
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
246
- - Hard Bug có khả năng tái diễn.
247
- - Pattern làm việc lặp lại trong dự án.
248
- - Convention hoặc quy tắc kiến trúc mới.
249
- - Quyết định Architecture quan trọng.
250
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
251
- - 👉 *Domain Harvest:* Quyết định Architecture quan trọng (vd: chuẩn index CSDL, quy tắc phân trang mới).
252
-
253
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
254
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
255
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
256
-
257
- ---
258
-
259
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
260
- Sau khi hoàn thành task:
261
- - AI đánh giá các Candidate Memory đã tạo.
262
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
263
- - Đề xuất người dùng xem xét.
264
- - Gửi yêu cầu phê duyệt thông qua:
265
- - `/learn`
266
- - `qk-project-memory`
267
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
268
-
269
- ```
270
- .ai-local/candidates/ ──(Approve)──> .agents/knowledge/index.yaml
271
- ```
272
-
273
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
274
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
275
-
276
- ---
277
-
278
- ### Ignore (Không đưa vào Memory)
279
- Không lưu:
280
- - Trace log của một session đơn lẻ.
281
- - Temporary debugging data.
282
- - Output của một lần chạy test/scan.
283
- - Report health tạm thời của một đợt kiểm tra.
284
- - Lỗi nhỏ chỉ xảy ra một lần.
285
- - Thông tin không có khả năng tái sử dụng.
286
- - 👉 *Domain Ignore:* Thao tác thêm trường đơn giản hoặc temporary database fix.
287
-
288
- ---
289
-
290
- ### Golden Rule
291
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
292
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
293
-
294
- ---
295
- ---
296
-
297
- ### Learning Flow (AI tự học có kiểm soát)
298
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
299
- - Hard Bug có khả năng tái diễn.
300
- - Pattern làm việc lặp lại trong dự án.
301
- - Convention hoặc quy tắc kiến trúc mới.
302
- - Quyết định Architecture quan trọng.
303
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
304
- - 👉 *Domain Harvest:* Quyết định Architecture quan trọng (vd: chuẩn index CSDL, quy tắc phân trang mới).
305
-
306
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
307
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
308
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
309
-
310
- ---
311
-
312
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
313
- Sau khi hoàn thành task:
314
- - AI đánh giá các Candidate Memory đã tạo.
315
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
316
- - Đề xuất người dùng xem xét.
317
- - Gửi yêu cầu phê duyệt thông qua:
318
- - `/learn`
319
- - `qk-project-memory`
320
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
321
-
322
- ```
323
- .ai-local/candidates/ ──(Approve)──> .agents/knowledge/index.yaml
324
- ```
325
-
326
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
327
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
328
-
329
- ---
330
-
331
- ### Ignore (Không đưa vào Memory)
332
- Không lưu:
333
- - Trace log của một session đơn lẻ.
334
- - Temporary debugging data.
335
- - Output của một lần chạy test/scan.
336
- - Report health tạm thời của một đợt kiểm tra.
337
- - Lỗi nhỏ chỉ xảy ra một lần.
338
- - Thông tin không có khả năng tái sử dụng.
339
- - 👉 *Domain Ignore:* Thao tác thêm trường đơn giản hoặc temporary database fix.
340
-
341
- ---
342
-
343
- ### Golden Rule
344
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
345
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
346
-
347
- ---
348
- ---
349
- ---
350
- ---
351
-
352
99
  ## Preconditions
353
- - [ ] Existing schema is identified (ORM model files)
354
- - [ ] Change intent is clear (add field / modify field / drop field)
355
100
 
356
- ```
357
- On missing precondition:
358
- EXIT: BLOCKED
359
- Message: "Cần xác định: schema hiện tại + loại thay đổi (add/modify/drop)."
360
- ```
361
-
362
- ---
101
+ Trước khi thay đổi bất kỳ file schema hay migration nào, AI BẮT BUỘC kiểm tra:
363
102
 
364
- ## Scope
365
- - ✅ Define strict schema BEFORE writing repository code
366
- - ✅ Always backward-compatible migrations (never destructive in first pass)
367
- - ✅ Separate schema (models) from business logic (services)
368
-
369
- ## Non-Goals
370
- - ❌ DROP columns without deprecation phase first
371
- - ❌ Write complex business logic inside repositories
372
- - ❌ Dynamic queries without schema definitions
103
+ - [ ] Xác định ORM/Tool đang dùng từ `DEV_PROFILE.md` (Prisma, Drizzle, TypeORM, Alembic, Knex, v.v.).
104
+ - [ ] Xác định Database engine (PostgreSQL, MySQL, SQLite, MongoDB).
105
+ - [ ] **Destructive check**: Thay đổi có chứa thao tác xóa/đổi tên cột (`DROP COLUMN`, `RENAME COLUMN`, thay đổi type thu hẹp dữ liệu) không?
106
+ - [ ] Nếu là thay đổi Destructive:
107
+ → **EXIT: BLOCKED**
108
+ → Báo cáo user: Cảnh báo rủi ro downtime và đề xuất áp dụng **Expand & Contract Pattern** thay vì drop/rename trực tiếp.
373
109
 
374
110
  ---
375
111
 
376
- ## Priority Order
377
- | P | Task | Skip Threshold |
378
- |---|------|----------------|
379
- | P1 | Read existing schema | Never |
380
- | P2 | Design migration (backward-compat) | Never |
381
- | P3 | Write migration file | Never |
382
- | P4 | Update repository layer | Budget < 30% |
383
- | P5 | Update affected service layer | Budget < 50% |
112
+ ## Scope
384
113
 
385
- ---
114
+ ✅ Skill này làm:
115
+ - Cập nhật file định nghĩa Schema (ví dụ `schema.prisma`, `schema.ts`, model files).
116
+ - Tạo migration scripts (SQL hoặc ORM-generated) có tính lũy tiến, an toàn.
117
+ - Thiết kế chiến lược **Expand & Contract** khi đổi tên cột hoặc tách bảng (Giai đoạn 1: Thêm cột mới + dual write; Giai đoạn 2: Backfill data; Giai đoạn 3: Deprecate & remove cột cũ).
118
+ - Đảm bảo các cột mới có `DEFAULT` value hoặc `NULLABLE` để tránh khóa bảng (table lock) hoặc lỗi insert từ code cũ đang chạy.
119
+ - Cập nhật types/interfaces tương ứng trong ứng dụng.
386
120
 
387
- ## Migration Safety Rules
388
- ```yaml
389
- add_column:
390
- strategy: nullable OR has default value (never NOT NULL without default)
391
-
392
- modify_column:
393
- strategy: add new column → migrate data → drop old column (3-phase)
394
-
395
- drop_column:
396
- strategy: Phase 1 — mark deprecated (keep in schema)
397
- Phase 2 — next release — remove from queries
398
- Phase 3 — next migration — DROP COLUMN
399
-
400
- rename_table:
401
- strategy: create new table → migrate → drop old (never ALTER TABLE RENAME in prod)
402
-
403
- pii_data:
404
- strategy: Khi add column chứa PII (Personal Identifiable Information), BẮT BUỘC áp dụng cơ chế hashing/encryption tương ứng (tuân thủ R-SEC-04).
405
- ```
121
+ ❌ Skill này KHÔNG làm:
122
+ - Chạy lệnh phá hủy tự động (`prisma migrate reset`, `drop database`, `truncate table`).
123
+ - Viết câu query phân tích hiệu năng/EXPLAIN (→ `qk-db-optimizer`).
124
+ - Viết API endpoint xử lý request/response (→ `qk-api-lifecycle`).
406
125
 
407
126
  ---
408
127
 
409
- ## Workflow
410
-
411
- ### Phase 1 — Schema Read
412
- 1. `grep_search` for existing model/entity file
413
- 2. Read current schema (targeted, ≤ 100 lines)
414
- 3. Identify impact of proposed change
415
-
416
- ### Phase 2 — Migration Design
417
- 1. Choose safety strategy (see Migration Safety Rules)
418
- 2. Write migration file (up + down)
419
- 3. Verify down() is always defined (rollback support)
420
-
421
- ### Phase 3 — Repository Update
422
- 1. Update repository methods to use new schema
423
- 2. Verify no raw queries reference old column names
128
+ ## Execution Steps
424
129
 
425
- **Decision:**
130
+ ### Step 1 — Phân tích Schema Diff & Đánh giá rủi ro
426
131
  ```
427
- IF migration is backward-compat AND down() defined → EXIT: SUCCESS
428
- ELSE IF destructive migration attempted → EXIT: BLOCKED — apply 3-phase strategy
132
+ Inputs: Schema hiện tại, Yêu cầu thay đổi từ user
133
+ Actions:
134
+ - So sánh schema cũ và mới.
135
+ - Phân loại:
136
+ - Safe: Thêm bảng mới, thêm nullable column, thêm column có default an toàn.
137
+ - Caution: Thêm index trên bảng lớn (cần CONCURRENTLY nếu Postgres).
138
+ - Dangerous: Xóa cột, đổi tên cột, đổi kiểu dữ liệu (Int -> String hoặc ngược lại).
139
+ Exit: BLOCKED nếu gặp Dangerous change mà chưa có kế hoạch Expand & Contract
429
140
  ```
430
141
 
431
- ---
432
-
433
- ## Evidence Format
142
+ ### Step 2 — Áp dụng Expand & Contract (nếu có Breaking Change)
434
143
  ```
435
- [SEVERITY] migration: [filename]
436
- Issue: [NOT NULL without default | missing down() | direct DROP]
437
- Confidence: HIGH
438
- Fix: [specific safer strategy]
144
+ Quy trình chuẩn:
145
+ 1. Expand: Thêm cột mới song song (nullable). Code ứng dụng ghi đồng thời cả 2 cột.
146
+ 2. Migrate Data: Chạy batch script chuyển dữ liệu từ cột cũ sang cột mới.
147
+ 3. Contract: Chuyển code đọc từ cột mới. Sau 1 release ổn định mới xóa cột cũ.
439
148
  ```
440
149
 
441
- ---
442
-
443
- ## Exit Codes
444
- | Code | Meaning | When |
445
- |------|---------|------|
446
- | SUCCESS | Schema, migration, and repository complete | Validated execution |
447
- | PARTIAL | Migration generated but untested | Missing DB connection |
448
- | BLOCKED | Fields or relationships ambiguous | Missing entity data |
449
- | FAILED | Migration involves destructive DROP without backup | Architecture violation |
450
-
451
- ---
150
+ ### Step 3 — Sinh Migration Script & Cập nhật ORM
151
+ ```
152
+ Actions:
153
+ - Sửa file schema chính (`schema.prisma`, Drizzle `schema.ts`, SQLAlchemy model).
154
+ - Tạo migration file có timestamp rõ ràng (VD: `20260914_add_phone_to_users.sql`).
155
+ - Đi kèm cả script Rollback (Down migration) nếu framework hỗ trợ.
156
+ - Chạy code generation cho types (VD: `npx prisma generate`).
157
+ ```
452
158
 
453
- ## Confidence Model
454
- | Level | Condition | Action |
455
- |-------|-----------|--------|
456
- | HIGH | Entity schema completely defined by user | Implement immediately |
457
- | MEDIUM | Schema inferred from JSON or forms | Ask for review before generating migration |
458
- | LOW | "Add database" request with no schema | EXIT: BLOCKED |
159
+ ### Step 4 — Verification
160
+ ```
161
+ Actions:
162
+ - Kiểm tra cú pháp SQL của migration file.
163
+ - Kiểm tra tính tương thích ngược: Code cũ vẫn insert/query được mà không crash.
164
+ - Kiểm tra Type definitions trong app có bị type error không (chạy tsc/type-check).
165
+ ```
459
166
 
460
167
  ---
461
168
 
462
- ## Severity
463
- | Level | Definition | Example |
464
- |-------|-----------|---------|
465
- | CRITICAL | Data loss risk in migration | Direct `DROP TABLE` without data copy |
466
- | HIGH | Missing index on foreign key | Performance degrade on JOIN |
467
- | MEDIUM | N+1 query vulnerability in repository | Fetching related entities in a loop |
468
- | LOW | Naming convention violation | `userId` instead of `user_id` in DB |
169
+ ## Prompt Template
469
170
 
470
- ---
471
-
472
- ## Retry Policy
473
171
  ```
474
- Migration generation fails
475
- └─ Syntax error in SQL/ORM
476
- ├─ Fix syntax based on engine (Postgres/MySQL)
477
- └─ Do NOT retry more than 1 time — risk of bad migration state
172
+ DB Engine: [PostgreSQL / MySQL / SQLite / MongoDB]
173
+ ORM/Tool: [Prisma / Drizzle / TypeORM / Alembic / Knex]
174
+ Thay đổi: [Thêm bảng mới / Thêm trường / Sửa quan hệ / Đổi kiểu dữ liệu]
175
+ Mục đích: [Mô tả nghiệp vụ cần lưu trữ]
176
+ Dữ liệu live: [Có dữ liệu production đang chạy không?]
478
177
  ```
479
178
 
480
- ---
179
+ ### Ví dụ theo Stack:
481
180
 
482
- ## Escalation Rules
181
+ **Prisma (PostgreSQL)**
483
182
  ```
484
- BLOCKED: Entity schema undefined
485
- Missing:
486
- - List of fields (types, constraints)
487
- - Relationships (1:1, 1:N, M:N)
488
- Questions:
489
- 1. Bảng này cần lưu những trường dữ liệu nào?
490
- 2. Bảng này có liên kết với bảng nào khác không? (ví dụ User)
491
- Recommended Assumptions:
492
- - Add standard created_at, updated_at timestamps
493
- - UUID primary keys
183
+ DB Engine: PostgreSQL
184
+ ORM: Prisma
185
+ Thay đổi: Thêm trường `phoneNumber` vào model `User`, không bắt buộc nhưng phải unique nếu có.
186
+ Dữ liệu live: Có (hơn 100k users)
494
187
  ```
188
+ → AI cập nhật: `phoneNumber String? @unique` trong `schema.prisma`, sinh migration SQL với `CREATE UNIQUE INDEX CONCURRENTLY` (nếu cần), chạy `prisma generate`.
495
189
 
496
- ---
497
-
498
- ## Handoff Contract
499
- ### Consumes
500
- ```json
501
- {
502
- "from": "user",
503
- "required_fields": ["entity_name", "fields"],
504
- "optional_fields": ["relationships", "db_engine"]
505
- }
190
+ **Drizzle ORM (MySQL)**
506
191
  ```
507
- ### Produces
508
- ```json
509
- {
510
- "to": "user or db-optimizer",
511
- "output_fields": ["schema_file", "migration_file", "repository_file", "exit_code"]
512
- }
192
+ DB Engine: MySQL
193
+ ORM: Drizzle
194
+ Thay đổi: Tạo bảng `AuditLog` lưu lịch sử hành động người dùng (id, userId, action, metadata JSON, createdAt).
513
195
  ```
514
-
515
- ---
196
+ → AI tạo: `auditLogs` table definition trong `src/db/schema.ts`, sinh migration file với Drizzle Kit, export type `AuditLog` và `NewAuditLog`.
516
197