[CLAUDE] PurchaseEvaluation: Mig 61 backfill EndedByLevelFinalize từ Changelogs (fix Mig 60 wrong-table) — phiếu finalize-CCM hết hiện sai "Đã được CEO duyệt" (anh Kiệt FDC UAT)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 5m12s

- Root-cause: Mig 60 backfill query PurchaseEvaluationApprovals cho marker "[Duyệt KẾT THÚC tại]", nhưng marker do LogTransitionAsync ghi vào PurchaseEvaluationChangelogs (approval-history là record riêng dòng :745) → match 0 dòng
- Phiếu finalize-sớm pre-Mig60 (PE/2026/A/005, A/008 — CCM Cấp 2 Phan Văn Chương duyệt-thay-CEO, KHÔNG qua CEO) giữ EndedByLevelFinalize=0 → endsBeforeCeo=False → badge SAI "Đã được CEO duyệt"
- Mig 61: backfill ĐÚNG bảng Changelogs (ContextNote LIKE N'%Duyệt KẾT THÚC tại%' + PhaseAtChange=7), idempotent, SQL-Server-only (tests SQLite no-replay)
- Verified prod: A/005/A/008 fin_marker=1 (finalize CCM) vs A/010 fin_marker=0 (CEO thật). gotcha #79

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-07-01 21:30:30 +07:00
parent 21be786c9e
commit fb2dfa9f7a
3 changed files with 6325 additions and 0 deletions

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SolutionErp.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class BackfillEndedByLevelFinalizeFromChangelog : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// [S97 anh Kiệt FDC — data-fix] Mig 60 backfill soi NHẦM bảng: nó query
// PurchaseEvaluationApprovals cho marker "[Duyệt KẾT THÚC tại...]", nhưng marker đó do
// LogTransitionAsync ghi vào PurchaseEvaluationChangelogs.ContextNote (approval-history
// là record RIÊNG ở dòng :745, LogTransition CHỈ ghi Changelog dòng :1073). → Mig 60
// match 0 dòng; phiếu finalize-sớm PRE-Mig60 (vd PE/2026/A/005, A/008 — Phan Văn Chương
// duyệt-thay-CEO tại CCM Cấp 2, KHÔNG qua CEO) giữ EndedByLevelFinalize=0 → hiển thị SAI
// "Đã được CEO duyệt" thay vì "Kết thúc tại CCM". Đính chính: set =1 cho phiếu DaDuyet có
// Changelog terminal (PhaseAtChange=7) chứa marker finalize. Idempotent (WHERE ...=0).
// SQL-Server-only (tests SQLite EnsureCreated no-replay migration, gotcha #63). Gotcha #79.
migrationBuilder.Sql(@"
UPDATE pe SET EndedByLevelFinalize = 1
FROM PurchaseEvaluations pe
WHERE pe.Phase = 7 AND pe.EndedByLevelFinalize = 0
AND EXISTS (
SELECT 1 FROM PurchaseEvaluationChangelogs c
WHERE c.PurchaseEvaluationId = pe.Id
AND c.PhaseAtChange = 7
AND c.ContextNote LIKE N'%Duyệt KẾT THÚC tại%');");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
// Data-fix đính chính (Mig 60 wrong-table) — KHÔNG reverse (không snapshot trạng thái
// trước; revert = tái tạo lỗi). No-op an toàn.
}
}
}