From 0b97840674b9c912644bc242ccd3d0c3ed654713 Mon Sep 17 00:00:00 2001 From: pqhuy1987 Date: Fri, 15 May 2026 15:07:57 +0700 Subject: [PATCH] =?UTF-8?q?[CLAUDE]=20Infra=20Api:=20Chunk=20T=20=E2=80=94?= =?UTF-8?q?=20Disable=20auto=20re-seed=20demo=20data=20qua=20DemoSeed:Disa?= =?UTF-8?q?bled=20flag=20(appsettings)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../appsettings.Development.json | 4 +++ src/Backend/SolutionErp.Api/appsettings.json | 4 +++ .../Persistence/DbInitializer.cs | 34 ++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Backend/SolutionErp.Api/appsettings.Development.json b/src/Backend/SolutionErp.Api/appsettings.Development.json index 9c6fec8..bb67798 100644 --- a/src/Backend/SolutionErp.Api/appsettings.Development.json +++ b/src/Backend/SolutionErp.Api/appsettings.Development.json @@ -17,5 +17,9 @@ "WriteTo": [ { "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 } } diff --git a/src/Backend/SolutionErp.Api/appsettings.json b/src/Backend/SolutionErp.Api/appsettings.json index 6fd4462..db516df 100644 --- a/src/Backend/SolutionErp.Api/appsettings.json +++ b/src/Backend/SolutionErp.Api/appsettings.json @@ -29,5 +29,9 @@ }, "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 } } diff --git a/src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs b/src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs index 6c1cad2..a7733f1 100644 --- a/src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs +++ b/src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; // Plan T S23 t10 — DemoSeed:Disabled flag using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using SolutionErp.Application.Contracts.Services; @@ -60,6 +61,23 @@ public static class DbInitializer logger.LogInformation("Applying migrations..."); 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(); + var demoSeedDisabled = config.GetValue("DemoSeed:Disabled"); + if (demoSeedDisabled) + logger.LogInformation("DemoSeed:Disabled=true — skip workflow + contracts + PE + sample V2 seed (Plan T S23 t10)"); + await SeedRolesAsync(roleManager, logger); // 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. @@ -71,8 +89,11 @@ public static class DbInitializer await SeedAdminPermissionsAsync(db, roleManager, logger); await SeedDemoMasterDataAsync(db, logger); await SeedContractTemplatesAsync(db, logger); - await SeedWorkflowDefinitionsAsync(db, logger); - await SeedPurchaseEvaluationWorkflowsAsync(db, logger); + if (!demoSeedDisabled) + { + await SeedWorkflowDefinitionsAsync(db, logger); + await SeedPurchaseEvaluationWorkflowsAsync(db, logger); + } await SeedCatalogsAsync(db, logger); // 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(); await BackfillContractCodesAsync(db, codeGen, logger); - await SeedDemoContractsAsync(db, userManager, codeGen, logger); - await SeedDemoPurchaseEvaluationsAsync(db, userManager, logger); - await SeedSampleApprovalWorkflowsV2Async(db, userManager, logger); + if (!demoSeedDisabled) + { + await SeedDemoContractsAsync(db, userManager, codeGen, logger); + await SeedDemoPurchaseEvaluationsAsync(db, userManager, logger); + await SeedSampleApprovalWorkflowsV2Async(db, userManager, logger); + } await WarnDefaultAdminPasswordAsync(userManager, logger); }