# database-agent — MEMORY (L1 HOT)

> READ-advisory DB specialist SOLUTION_ERP (.NET 10 EF Core 10 + SQL Server, single `ApplicationDbContext` dbo). Adopt AI_INFRA broadcast `2026-06-08-Agent-database-codebase-agents` (floor DB1–DB11), S52 2026-06-08. Seed = em main. **Nấc hiện: executed-file — verified-runtime CHỜ anh restart CLI + spawn-test.**

## Vai trò (FORM tailored SE)
- **READ-advisory tier** — DESIGN/REVIEW/PERF/CONCURRENCY-advise, KHÔNG author file. `implementer-backend` author entity+config+migration; em main solo quyết schema-design cuối. database-agent = deep-DB lens hỗ trợ + review.
- Floor DB1–DB11 (canonical, KHÔNG hạ) — chi tiết `.claude/agents/database-agent.md`.
- Skill: `sql-database-assistant` (SQL Server raw, KHÔNG cover EF-Core) + `ef-core-migration` (EF Core 10 pin + 3-file rule). Verify present TRƯỚC wire.
- `store_memory` STRIPPED → ghi finding vào FILE này; em main + re-index → RAG.

## SE facts cốt lõi (DB10 evidence-based — re-ground khi cần)
- **45 migration → 92 tables** (S51). `sys.tables` = ground-truth (narrative count drift "incremented-per-session" → re-ground).
- 2 DB instance: LocalDB `SolutionErp_Dev` (runtime) / `SolutionErp_Design` (design-time) — gotcha designtime-vs-runtime DB (apply migration cả 2 qua `--connection` override). Prod = `.\SQLEXPRESS\SolutionErp`.
- Soft-delete UNIQUE index PHẢI `.HasFilter("[IsDeleted]=0")` (gotcha #57 — 13× pattern; S45 Holiday + S51 LeaveType/Shift/OtPolicy/Vehicle/Driver). EXT backlog: Department/Supplier/Project (Mig 46 worktree).
- Codegen atomic = `WorkflowAppCodeGen.GenerateMaDonTuAsync` dùng `IsolationLevel.Serializable` tx (Prefix-keyed sequence) — pattern ĐÚNG tham chiếu cho concurrency.

## 🎯 DB11 gap đã biết (concurrency — vai trò chính)
- **S43 LeaveBalance trừ phép KHÔNG có `RowVersion`** = lost-update risk khi 2 approve đua (concurrency token defer). = lý do AI_INFRA tag database-agent STRONG-FIT cho SE.
- P11-D SLA flags (`SlaWarnedSent`/`SlaBreached`) + P11-F codegen = concurrency-sensitive → DB11 lens áp được.

## Boundary (⟂)
- vs implementer-backend: DESIGN/REVIEW vs AUTHOR (KHÔNG double-touch migration file).
- vs investigator-codebase: deep DB-layer (introspection/query-plan/concurrency) vs broad grep/audit.
- vs reviewer: DB-layer design-review (DB6/DB11/DB5) TRƯỚC author vs adversarial pre-commit cross-stack.
- KHÔNG: FE · business-logic · deploy · session-lifecycle audit.

## Accuracy (G-015)
- DB7 scope-DB-only = PHÂN-VAI, KHÔNG "read-only enforced" (giữ `Bash` → write-channel shell mở; containment = em main single-writer + git-diff post-session).
- Schema/perf-claim từ introspection THẬT (`sqlcmd`/`dotnet ef`), KHÔNG narrative.

## Log
- **S52 (2026-06-08):** Seeded (em main, adap-apply database-agent). Roster 10→11. Nấc executed-file. CHỜ restart + spawn-test → verified-runtime.
