[CLAUDE] Docs: S44 monthly drift audit + AI_INFRA bundle 06-01 adopt

Cadence audit (2026-06-01), docs-only -> CI-skip. investigator-codebase
drift scan (ground-truth from disk) -> em main patch. No code touched,
154 test unchanged.

Drift fixes (42 count corrections): 40->42 mig, 84/59/55/47->91 tables,
130/111->154 test, 52/49->56 gotcha across CLAUDE.md, docs/CLAUDE.md,
ef-core-migration + dependency-audit skills, schema-diagram, database-guide.
schema-diagram migration table extended Mig 17-42; ef-core history Mig 27-42;
detailed-section gap (Mig 27-42 modules) flagged explicit (deferred, not silent).

AI_INFRA bundle 06-01 (federated, full scope):
- A: RAG T1/T2 auto-ack
- C: hygiene 7/7 agent-mem L1 <=16KB; "25KB"->"~30KB tiered" wording x7
- D: #4 self-sustaining adoption-report step -> /session-end Phase 6.3
- E/F: report + ledger -> docs/governance/

Carry-over .mcp.json + BROADCAST-05-29 left untouched (concurrency rule).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-06-01 12:39:56 +07:00
parent 197c72f352
commit ae30f8f5e2
17 changed files with 160 additions and 42 deletions

View File

@ -1,6 +1,6 @@
---
name: ef-core-migration
description: Tạo/sửa/revert EF Core 10 migration cho SOLUTION_ERP. Dùng khi thêm entity mới, thay đổi schema, rollback migration, debug DesignTimeDbContextFactory fail. Đã có 31 migration sẵn (Init → RefactorSkipToFinalToApproverLevel Mig 31 S23 t1 F2 per-Approver-slot swap). Snapshot + Designer + Migration 3-file rule bắt buộc commit đủ.
description: Tạo/sửa/revert EF Core 10 migration cho SOLUTION_ERP. Dùng khi thêm entity mới, thay đổi schema, rollback migration, debug DesignTimeDbContextFactory fail. Đã có 42 migration sẵn (Init → AddLeaveBalances Mig 42, S43 Phase 11 P11-B). Snapshot + Designer + Migration 3-file rule bắt buộc commit đủ.
when-to-use:
- "thêm migration"
- "EF Core migration"
@ -16,7 +16,7 @@ when-to-use:
> **Context:** .NET 10 + EF Core 10 + SQL Server. DbContext: `ApplicationDbContext` ở `Infrastructure/Persistence/`. Startup: `SolutionErp.Api`.
## Migration history (31 migration hiện có)
## Migration history (42 migration hiện có)
| # | Name | Tables added / changed |
|---|---|---|
@ -46,8 +46,24 @@ when-to-use:
| **24** | **`AddCurrentApprovalLevelOrderToPe`** | **Service V2 wire — `PE.CurrentApprovalLevelOrder int?` track Cấp đang chờ trong Step hiện tại khi pin ApprovalWorkflowId. Null khi V1 legacy hoặc terminal. Service `ApproveV2Async` group Levels by Order = Cấp (OR-of-N), match `actor.Id ∈ ApproverUserId`, advance levelOrder++ trong Step → idx++ + reset levelOrder=1 → DaDuyet. Synthetic Policy `ForV2Schema()` cho FE nextPhases. Session 17.** |
| **25** | **`AddIsUserSelectableToApprovalWorkflows`** | **ALTER `ApprovalWorkflows` +`IsUserSelectable bit NOT NULL DEFAULT 0` — admin pin/unpin workflow cho user pick lúc create phiếu (multi-select, độc lập IsActive — multiple version cùng selectable). Backfill `WHERE IsActive=1 SET 1` giữ behavior cũ (active workflows vẫn pickable). Designer +badge "Cho user chọn" + button Ghim/Bỏ ghim + mutation toggle. Workspace dropdown filter `isUserSelectable=true` only. API `PATCH /api/approval-workflows-v2/{id}/user-selectable` admin-only. Session 18 (2026-05-08).** |
| **26** | **`AddPeLevelOpinionsForV2`** | **🎯 Section 5 dynamic theo Workflow V2 (Session 19, 2026-05-09) — bảng mới `PurchaseEvaluationLevelOpinions` UNIQUE composite (PEId, ApprovalWorkflowLevelId), FK Cascade Pe + Restrict Level. Comment nvarchar(2000) + SignedAt + SignedByUserId + SignedByFullName denorm. Service `ApproveV2Async` UPSERT auto khi NV duyệt (Q1=1B sync gắn với Duyệt, KHÔNG endpoint CRUD rời). Match level theo ApproverUserId; Admin override fallback first level (FE banner "Admin duyệt thay" khi SignedByUserId !== ApproverUserId). Comment empty → "(duyệt — không ý kiến)" placeholder Q4 bonus. Phiếu V1 legacy fallback Mig 15 4 box readOnly. Mig 15 deprecated cho V2 phiếu (drop sau UAT confirm Mig 27+).** |
| **27** | **`AddVisibilityAndDisplayLabelToMenuItems`** | **2 ALTER `MenuItems` (+`IsVisible bit`=1 +`DisplayLabel nvarchar(200)?`) — admin ẩn/hiện + đổi tên menu eOffice (fe-user). Không bảng mới. Session 20.** |
| **28** | **`AddAdvancedOptionsToApprovalWorkflows`** | **ALTER `ApprovalWorkflows` — advanced options (skip/optional level config). Session 22.** |
| **29** | **`RefactorAdvancedOptionsToPerLevelAndDrafterUser`** | **Refactor advanced options → per-`ApprovalWorkflowLevel` + DrafterUser scope. Session 22.** |
| **30** | **`AddAllowApproverEditBudgetToLevels`** | **ALTER `ApprovalWorkflowLevels` +`AllowApproverEditBudget bit`. Session 22.** |
| **31** | **`RefactorSkipToFinalToApproverLevel`** | **Per-Approver-slot skip-to-final (Level → Approver slot swap). Session 23.** |
| **32** | **`AddApprovalWorkflowToContract`** | **🎯 Contract V2 wire (Plan B S29) — 2 ALTER `Contracts` (+`ApprovalWorkflowId Guid?` +`CurrentApprovalLevelOrder int?`) cookie-cutter mirror PE Mig 23+24. Không bảng mới.** |
| **33** | **`AddContractLevelOpinions`** | **1 bảng `ContractLevelOpinions` (UNIQUE composite ContractId+LevelId, FK Cascade Contract + Restrict Level) — mirror PE Mig 26. Session 29.** |
| **34** | **`AddEmployeeProfiles`** | **HRM core — `EmployeeProfiles` + N satellite tables cùng parent (Pattern 12-ter). Session 34.** |
| **35** | **`AddHrmConfigs`** | **HRM config catalogs (LeaveTypes / Holidays UNIQUE composite / declarative KIND_CONFIG). Session 35.** |
| **36** | **`AddMeetingRooms`** | **Office — `MeetingRooms` + booking. Session 36-37.** |
| **37** | **`ExtendApplicableTypeForWorkflowApps`** | **Enum extend `ApplicableType` (+Proposal +WorkflowApps values). Không bảng mới. Session 37-38.** |
| **38** | **`AddProposals`** | **Module Đề xuất (Proposal) — tables + workflow V2 mirror PE/Contract. Session 37.** |
| **39** | **`AddWorkflowApps`** | **Workflow Apps skeleton — Leave/OT/Travel/Vehicle/Ticket request tables (Phase 10 Plan G-O4/O5). Session 38.** |
| **40** | **`AddAttendances`** | **Chấm công (Attendance) tables + Dashboard NS skeleton. Session 38.** |
| **41** | **`WireWorkflowAppsApprovalV2`** | **🎯 Phase 11 P11-A (S42) — +4 `{Leave,Ot,Travel,Vehicle}LevelOpinions` (UNIQUE composite + Cascade/Restrict) + `WorkflowAppCodeSequences` (atomic MaDonTu) + 4 ALTER `RejectedFromStatus` + enum `TravelRequest=9`.** |
| **42** | **`AddLeaveBalances`** | **🎯 Phase 11 P11-B (S43) — 1 bảng `LeaveBalances` (User×LeaveType×Year + Entitled/Used/Adjustment, UNIQUE composite + FK LeaveTypes Restrict). Trừ phép tự động khi đơn nghỉ duyệt cuối.** |
Total: **59 bảng** dbo + `__EFMigrationsHistory` (Mig 22 add 3 V2 + Mig 26 add 1 PE Level Opinions). Xem `docs/database/schema-diagram.md` ERD đầy đủ + §14 ApprovalWorkflow V2 + §15 PE Level Opinions V2.
Total: **91 bảng** dbo + `__EFMigrationsHistory` (last Mig 42 AddLeaveBalances). Xem `docs/database/schema-diagram.md` migration table + §11-15 module ERD (§16+ Mig 27-42 chi tiết pending).
## N-stage workflow pattern (Mig 18-20 — Session 12-13)
@ -77,7 +93,7 @@ Architecture decision đáng ghi cho session sau:
**Phase 8 update (2026-04-29 Session 5):**
- Migration 15 `AddPurchaseEvaluationDepartmentOpinions` — 1 bảng riêng (UNIQUE PEId+Kind), max 4 row mỗi phiếu cho 4 phòng ban (Phê duyệt/Ccm/MuaHang/SmPm). UPDATE in-place khi user đổi ý, audit qua Changelog.
- Tests Phase 1-2-3mini live + cumulative S22-S25 regression tests: `tests/SolutionErp.Domain.Tests/` (58 test policy state machine) + `tests/SolutionErp.Infrastructure.Tests/` (53 test = 17 codegen + 7 PE 2-stage + 7 PE N-stage + 6 PE WF + 5 AuthorizePolicy + 4 TraLai + 2 Plan M edge case + 1 V2 actor scope + 4 Approver F2/lookup regression). **Total 111 test pass / ~5s**. S22-S23 +20 cumulative regression: ReturnMode + DraftGuard + Reflection AuthorizePolicy + V2 actor scope reject + per-NV lookup discrimination (Plan N+O). Mig 21 drop 19 legacy (PE 2-stage S9 + PE N-stage S12 + Contract N-stage S13 + PE Reject S14) — flat workflow stabilized post-S22 V2 ground truth.
- Tests: `tests/SolutionErp.Domain.Tests/` (58 test policy state machine) + `tests/SolutionErp.Infrastructure.Tests/` (96 test = codegen + 2-stage/N-stage + AuthorizePolicy + V2 actor scope + WorkflowApps ApproveV2 + LeaveBalance/guard). **Total 154 test pass** (current S43; S22-S25 baseline was 111). S22-S23 +20 cumulative regression: ReturnMode + DraftGuard + Reflection AuthorizePolicy + V2 actor scope reject + per-NV lookup discrimination (Plan N+O). Mig 21 drop 19 legacy (PE 2-stage S9 + PE N-stage S12 + Contract N-stage S13 + PE Reject S14) — flat workflow stabilized post-S22 V2 ground truth.
- CI optimize 3 fix (29/04):
- Manual checkout bypass github.com (gotcha #39) — fix TCP timeout 21s
- Path filter docs-only skip (gotcha #41) — commit MD-only KHÔNG trigger CI
@ -255,7 +271,7 @@ sqlcmd -S .\SQLEXPRESS -d SolutionErp -U vrapp -P <pw> -i migrate.sql
## Code pointers
- `src/Backend/SolutionErp.Infrastructure/Persistence/ApplicationDbContext.cs` — DbSet cho 59 bảng (31 migration)
- `src/Backend/SolutionErp.Infrastructure/Persistence/ApplicationDbContext.cs` — DbSet cho 91 bảng (42 migration)
- `src/Backend/SolutionErp.Infrastructure/Persistence/DesignTimeDbContextFactory.cs` — EF tooling factory
- `src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs` — seed + warn + migrate runtime + backfill (idempotent reconcile pattern)
- `src/Backend/SolutionErp.Infrastructure/Persistence/Configurations/` — IEntityTypeConfiguration<T> per entity
@ -264,5 +280,5 @@ sqlcmd -S .\SQLEXPRESS -d SolutionErp -U vrapp -P <pw> -i migrate.sql
## Related
- `docs/database/database-guide.md` — conventions + migration workflow chi tiết
- `docs/database/schema-diagram.md`**ERD 59 bảng** + §11 PE module + §12 Budget module + §13 PEDeptOpinions (Mig 15) + §14 ApprovalWorkflow V2 (Mig 22-25) + §15 PE Level Opinions V2 (Mig 26)
- `docs/database/schema-diagram.md`**ERD 91 bảng** + §11 PE + §12 Budget + §13 PEDeptOpinions (Mig 15) + §14 ApprovalWorkflow V2 (Mig 22-25) + §15 PE Level Opinions V2 (Mig 26); §16+ Mig 27-42 detail pending (xem migration table)
- `docs/gotchas.md` #7, #17, #38 — migration pitfalls + Identity 4-field rename