fix(data-foundation): 对齐治理应用迁移历史门禁

This commit is contained in:
WuYongJie 2026-06-04 20:20:31 +08:00
parent d6ac21db0e
commit 3cd1102cd2
3 changed files with 32 additions and 3 deletions

View File

@ -116,10 +116,15 @@ function writeJsonReport(outputPath, payload, rootDir = ROOT_DIR) {
} }
function migrationHistoryReady(migrationHistory = {}) { function migrationHistoryReady(migrationHistory = {}) {
const unresolvedRolledBackMigrationRows =
migrationHistory.unresolvedRolledBackMigrationRows == null
? migrationHistory.rolledBackMigrationRows
: migrationHistory.unresolvedRolledBackMigrationRows
return ( return (
migrationHistory.tableExists === true && migrationHistory.tableExists === true &&
migrationHistory.unfinishedMigrationRows === 0 && migrationHistory.unfinishedMigrationRows === 0 &&
migrationHistory.rolledBackMigrationRows === 0 unresolvedRolledBackMigrationRows === 0
) )
} }
@ -251,7 +256,7 @@ function buildFoundationRequiredMigrationApplyPlan(readiness, options = {}) {
if (!migrationHistoryReady(readiness.migrationHistory)) { if (!migrationHistoryReady(readiness.migrationHistory)) {
blockers.push({ blockers.push({
key: 'migrationHistory.notReady', key: 'migrationHistory.notReady',
message: '治理迁移/护栏真实应用前,必须先补齐 _prisma_migrations 历史且无失败/回滚记录。', message: '治理迁移/护栏真实应用前,必须先补齐 _prisma_migrations 历史且无失败/未解决回滚记录。',
}) })
} }
if (phase === 'finalize' && readiness.pendingStructureMigrationCount > 0) { if (phase === 'finalize' && readiness.pendingStructureMigrationCount > 0) {

View File

@ -914,6 +914,10 @@ function buildBaselineRepairPlanSummary(baselineRepairPlan) {
function buildFoundationRequiredMigrationApplyPlanSummary(applyPlan) { function buildFoundationRequiredMigrationApplyPlanSummary(applyPlan) {
if (!applyPlan) return null if (!applyPlan) return null
const unresolvedRolledBackMigrationRows =
applyPlan.migrationHistory?.unresolvedRolledBackMigrationRows == null
? applyPlan.migrationHistory?.rolledBackMigrationRows
: applyPlan.migrationHistory?.unresolvedRolledBackMigrationRows
return { return {
mode: applyPlan.mode || '', mode: applyPlan.mode || '',
dryRun: applyPlan.dryRun !== false, dryRun: applyPlan.dryRun !== false,
@ -924,7 +928,7 @@ function buildFoundationRequiredMigrationApplyPlanSummary(applyPlan) {
migrationHistoryReady: migrationHistoryReady:
applyPlan.migrationHistory?.tableExists === true && applyPlan.migrationHistory?.tableExists === true &&
applyPlan.migrationHistory?.unfinishedMigrationRows === 0 && applyPlan.migrationHistory?.unfinishedMigrationRows === 0 &&
applyPlan.migrationHistory?.rolledBackMigrationRows === 0, unresolvedRolledBackMigrationRows === 0,
blockerKeys: Array.isArray(applyPlan.blockers) blockerKeys: Array.isArray(applyPlan.blockers)
? applyPlan.blockers.map((blocker) => blocker.key).filter(Boolean) ? applyPlan.blockers.map((blocker) => blocker.key).filter(Boolean)
: [], : [],

View File

@ -23,6 +23,8 @@ function readiness(overrides = {}) {
appliedMigrationRows: 86, appliedMigrationRows: 86,
unfinishedMigrationRows: 0, unfinishedMigrationRows: 0,
rolledBackMigrationRows: 0, rolledBackMigrationRows: 0,
resolvedRolledBackMigrationRows: 0,
unresolvedRolledBackMigrationRows: 0,
}, },
migrationCount: 43, migrationCount: 43,
readyMigrationCount: 11, readyMigrationCount: 11,
@ -77,15 +79,33 @@ describe('apply-master-data-foundation-migrations', () => {
it('requires clean Prisma migration history before applying foundation guards', () => { it('requires clean Prisma migration history before applying foundation guards', () => {
expect(migrationHistoryReady(readiness().migrationHistory)).toBe(true) expect(migrationHistoryReady(readiness().migrationHistory)).toBe(true)
expect(migrationHistoryReady({
tableExists: true,
unfinishedMigrationRows: 0,
rolledBackMigrationRows: 11,
resolvedRolledBackMigrationRows: 11,
unresolvedRolledBackMigrationRows: 0,
})).toBe(true)
expect(migrationHistoryReady({ expect(migrationHistoryReady({
tableExists: false, tableExists: false,
unfinishedMigrationRows: 0, unfinishedMigrationRows: 0,
rolledBackMigrationRows: 0, rolledBackMigrationRows: 0,
resolvedRolledBackMigrationRows: 0,
unresolvedRolledBackMigrationRows: 0,
})).toBe(false) })).toBe(false)
expect(migrationHistoryReady({ expect(migrationHistoryReady({
tableExists: true, tableExists: true,
unfinishedMigrationRows: 1, unfinishedMigrationRows: 1,
rolledBackMigrationRows: 0, rolledBackMigrationRows: 0,
resolvedRolledBackMigrationRows: 0,
unresolvedRolledBackMigrationRows: 0,
})).toBe(false)
expect(migrationHistoryReady({
tableExists: true,
unfinishedMigrationRows: 0,
rolledBackMigrationRows: 11,
resolvedRolledBackMigrationRows: 10,
unresolvedRolledBackMigrationRows: 1,
})).toBe(false) })).toBe(false)
}) })