# Real-data master import via UNGATED DbInitializer seed (S55)

**When:** nạp real company master data (Excel → bảng có sẵn Project/Supplier/WorkItem). User sẽ làm tiếp (full NCC list, thêm dự án).

**Mechanism = idempotent DbInitializer seed** (KHÔNG API loop — no bulk endpoint tồn tại; KHÔNG manual SQL).
- **KEY ungated:** `SeedDemoMasterDataAsync` (Supplier/Project) + `SeedCatalogsAsync` (WorkItem) gọi NGOÀI gate `if(!demoSeedDisabled)` (DbInitializer ~line 108/115) → master/catalog seed **reaches prod by design** (DbInitializer:75 comment "GIỮ … SeedDemoMasterData/Catalogs" kể cả DemoSeed:Disabled=true). Prod `appsettings.json` DemoSeed:Disabled=true CHỈ gate transactional demo (contracts/PE/workflows).
- Mirror: NEW `SeedRealMasterDataAsync` = 3 tuple-loop **per-code idempotent** (`existingCodes.Contains(code)→continue; else Add`, pattern dòng ~2185), wired **ungated** sau SeedCatalogsAsync → real data tự lên prod khi deploy, coexist demo, re-run safe (expand-over-time).
- `WorkItem` master ĐÃ tồn tại (Code/Name/Category/IsActive) → Hạng mục categories fit, NO new table. Thêm field Project = migration AddColumn (no new table).

**Discipline real-data accuracy:**
1. Extract Excel → **clean generated-spec file** (`scripts/*.generated.md`) — chống brief-truncation khi nhồi 100+ rows vào agent brief; implementer Read file → convert C# inline arrays.
2. Đọc cấu trúc Excel THẬT trước map (merged col, divider row — vd MEP col gộp MEP-Sub + "THIẾT BỊ" divider → split đúng, đừng lùa divider thành item).
3. **Runtime Dev proof TRƯỚC prod:** chạy API trên Dev (DbInitializer seed) → sqlcmd spot-check real codes + **N-literal cho unicode field** (`WHERE Investor=N'...'`, sqlcmd console mangle dấu ≠ data corruption) → bắt maxlength-overflow/dup-crash trước.
4. cicd sqlcmd spot-check prod sau deploy.

**Collision** (real code == demo code, vd FLOCK01): per-code skip → demo thắng. Acceptable (real code+year-only); note cho manual fix qua UI.

**S55 proof:** 62 Projects + 71 WorkItems + 3 Suppliers, Mig 48 `AddProjectMasterFields`, commit `69cb393` Run #377, prod-verified all spot-checks.
