[CLAUDE] Infra Api: Chunk T — Disable auto re-seed demo data qua DemoSeed:Disabled flag (appsettings)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m22s

Bro UAT post-Plan R+S phát hiện: 4 phiếu [DEMO]-A/B + 2 V1 workflows + 1
V2 sample TỰ ĐỘNG RE-SEED sau BE deploy commits Plan P+Q+R+S → IIS recycle
→ DbInitializer.InitializeAsync auto-seed lại 5 demo seed methods.

Plan T fix root cause: Config flag `DemoSeed:Disabled` trong
appsettings.json (production default true) → DbInitializer check flag →
skip 5 demo seed methods.

Note: appsettings.Production.json bị .gitignore (chứa secrets prod), nên
em set flag mặc định trong appsettings.json (commit qua git) — production
inherit true. Dev override false trong appsettings.Development.json để
test fresh demo seed local.

Methods SKIP khi DemoSeed:Disabled=true:
1. SeedWorkflowDefinitionsAsync (V1 PE workflow QT-DN-A v1 + QT-DN-B v1)
2. SeedPurchaseEvaluationWorkflowsAsync (V1 PE workflow extended)
3. SeedDemoContractsAsync ([DEMO] HĐ 7-type sample)
4. SeedDemoPurchaseEvaluationsAsync ([DEMO] PE 4 sample with V1 pin)
5. SeedSampleApprovalWorkflowsV2Async (V2 sample mẫu UAT type B)

Methods KEEP (luôn chạy):
- SeedRoles + SeedAdmin + SeedDepartments + SeedDemoUsers (30 UAT users)
- SeedMenuTree + SeedAdminPermissions + SeedDemoMasterData (Supplier/Project)
- SeedContractTemplates + SeedCatalogs + BackfillContractCodes
- BackfillUserEmailDomain (Phase 6 rebrand migration helper)

Files changed:
- src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs:
  + using Microsoft.Extensions.Configuration
  + Read DemoSeed:Disabled flag từ IConfiguration
  + Log "DemoSeed:Disabled=true — skip ..." khi flag true
  + Wrap 5 method seed conditional `if (!demoSeedDisabled) { ... }`

- src/Backend/SolutionErp.Api/appsettings.json:
  + "DemoSeed": { "Disabled": true } + comment narrative

- src/Backend/SolutionErp.Api/appsettings.Development.json:
  + "DemoSeed": { "Disabled": false } override cho dev

Workflow expected sau deploy:
1. CI deploy commit T → IIS recycle app pool
2. BE startup → DbInitializer reads DemoSeed:Disabled=true
3. Skip 5 demo seed methods → DB state preserved
4. Bro UAT clean slate hoàn toàn — Designer setup workflow mới from scratch

Pending T5: Final DELETE current state (4 PE + 2 V1 + 1 V2 mẫu UAT) sau
deploy applied flag. T6 verify no re-seed loop sau re-deploy.

Verify:
- dotnet build SolutionErp.slnx clean (0 err, 2 warn pre-existing)
- dotnet test SolutionErp.slnx **111/111 PASS** unchanged

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-05-15 15:07:57 +07:00
parent c4d5704269
commit 0b97840674
3 changed files with 37 additions and 5 deletions

View File

@ -17,5 +17,9 @@
"WriteTo": [ "WriteTo": [
{ "Name": "Console" } { "Name": "Console" }
] ]
},
"DemoSeed": {
"_Comment": "Plan T S23 t10 — Dev override: false để test demo seed local. Production appsettings.json mặc định true (skip).",
"Disabled": false
} }
} }

View File

@ -29,5 +29,9 @@
}, },
"Uploads": { "Uploads": {
"RootPath": "uploads" "RootPath": "uploads"
},
"DemoSeed": {
"_Comment": "Plan T S23 t10 (2026-05-15) — DbInitializer skip auto re-seed Demo workflows + PE + Contracts khi true. Production UAT clean slate sau Plan R+S. Dev override false trong appsettings.Development.json để test fresh seed local.",
"Disabled": true
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; // Plan T S23 t10 — DemoSeed:Disabled flag
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SolutionErp.Application.Contracts.Services; using SolutionErp.Application.Contracts.Services;
@ -60,6 +61,23 @@ public static class DbInitializer
logger.LogInformation("Applying migrations..."); logger.LogInformation("Applying migrations...");
await db.Database.MigrateAsync(); await db.Database.MigrateAsync();
// Plan T S23 t10 (2026-05-15) — DemoSeed:Disabled flag. Khi true thì skip
// 5 method auto-seed demo data:
// - SeedWorkflowDefinitionsAsync (V1 PE workflow sample: QT-DN-A + QT-DN-B)
// - SeedPurchaseEvaluationWorkflowsAsync (V1 PE workflow extended)
// - SeedDemoContractsAsync ([DEMO] HĐ 7-type sample)
// - SeedDemoPurchaseEvaluationsAsync ([DEMO] PE 4 sample)
// - SeedSampleApprovalWorkflowsV2Async (V2 sample mẫu UAT cho type B)
// GIỮ: SeedRoles, SeedAdmin, SeedDepartments, SeedDemoUsers (30 user UAT),
// SeedMenuTree, SeedAdminPermissions, SeedDemoMasterData (Supplier/Project
// master), SeedContractTemplates (file template), SeedCatalogs, backfill
// helpers. Production UAT clean slate: bro toàn quyền setup workflow mới
// qua Designer.
var config = sp.GetRequiredService<IConfiguration>();
var demoSeedDisabled = config.GetValue<bool>("DemoSeed:Disabled");
if (demoSeedDisabled)
logger.LogInformation("DemoSeed:Disabled=true — skip workflow + contracts + PE + sample V2 seed (Plan T S23 t10)");
await SeedRolesAsync(roleManager, logger); await SeedRolesAsync(roleManager, logger);
// Phase 6 rebrand: rename user email @solutionerp.local → @solutions.com.vn // Phase 6 rebrand: rename user email @solutionerp.local → @solutions.com.vn
// TRƯỚC SeedAdmin để SeedAdmin tìm theo new email thấy user đã rename → skip create. // TRƯỚC SeedAdmin để SeedAdmin tìm theo new email thấy user đã rename → skip create.
@ -71,8 +89,11 @@ public static class DbInitializer
await SeedAdminPermissionsAsync(db, roleManager, logger); await SeedAdminPermissionsAsync(db, roleManager, logger);
await SeedDemoMasterDataAsync(db, logger); await SeedDemoMasterDataAsync(db, logger);
await SeedContractTemplatesAsync(db, logger); await SeedContractTemplatesAsync(db, logger);
if (!demoSeedDisabled)
{
await SeedWorkflowDefinitionsAsync(db, logger); await SeedWorkflowDefinitionsAsync(db, logger);
await SeedPurchaseEvaluationWorkflowsAsync(db, logger); await SeedPurchaseEvaluationWorkflowsAsync(db, logger);
}
await SeedCatalogsAsync(db, logger); await SeedCatalogsAsync(db, logger);
// Backfill mã HĐ cho HĐ legacy chưa có (sau khi đổi policy gen-tại-create). // Backfill mã HĐ cho HĐ legacy chưa có (sau khi đổi policy gen-tại-create).
@ -80,9 +101,12 @@ public static class DbInitializer
var codeGen = sp.GetRequiredService<IContractCodeGenerator>(); var codeGen = sp.GetRequiredService<IContractCodeGenerator>();
await BackfillContractCodesAsync(db, codeGen, logger); await BackfillContractCodesAsync(db, codeGen, logger);
if (!demoSeedDisabled)
{
await SeedDemoContractsAsync(db, userManager, codeGen, logger); await SeedDemoContractsAsync(db, userManager, codeGen, logger);
await SeedDemoPurchaseEvaluationsAsync(db, userManager, logger); await SeedDemoPurchaseEvaluationsAsync(db, userManager, logger);
await SeedSampleApprovalWorkflowsV2Async(db, userManager, logger); await SeedSampleApprovalWorkflowsV2Async(db, userManager, logger);
}
await WarnDefaultAdminPasswordAsync(userManager, logger); await WarnDefaultAdminPasswordAsync(userManager, logger);
} }