fix(data-foundation): 对齐治理应用迁移历史门禁
This commit is contained in:
parent
d6ac21db0e
commit
3cd1102cd2
@ -116,10 +116,15 @@ function writeJsonReport(outputPath, payload, rootDir = ROOT_DIR) {
|
||||
}
|
||||
|
||||
function migrationHistoryReady(migrationHistory = {}) {
|
||||
const unresolvedRolledBackMigrationRows =
|
||||
migrationHistory.unresolvedRolledBackMigrationRows == null
|
||||
? migrationHistory.rolledBackMigrationRows
|
||||
: migrationHistory.unresolvedRolledBackMigrationRows
|
||||
|
||||
return (
|
||||
migrationHistory.tableExists === true &&
|
||||
migrationHistory.unfinishedMigrationRows === 0 &&
|
||||
migrationHistory.rolledBackMigrationRows === 0
|
||||
unresolvedRolledBackMigrationRows === 0
|
||||
)
|
||||
}
|
||||
|
||||
@ -251,7 +256,7 @@ function buildFoundationRequiredMigrationApplyPlan(readiness, options = {}) {
|
||||
if (!migrationHistoryReady(readiness.migrationHistory)) {
|
||||
blockers.push({
|
||||
key: 'migrationHistory.notReady',
|
||||
message: '治理迁移/护栏真实应用前,必须先补齐 _prisma_migrations 历史且无失败/回滚记录。',
|
||||
message: '治理迁移/护栏真实应用前,必须先补齐 _prisma_migrations 历史且无失败/未解决回滚记录。',
|
||||
})
|
||||
}
|
||||
if (phase === 'finalize' && readiness.pendingStructureMigrationCount > 0) {
|
||||
|
||||
@ -914,6 +914,10 @@ function buildBaselineRepairPlanSummary(baselineRepairPlan) {
|
||||
|
||||
function buildFoundationRequiredMigrationApplyPlanSummary(applyPlan) {
|
||||
if (!applyPlan) return null
|
||||
const unresolvedRolledBackMigrationRows =
|
||||
applyPlan.migrationHistory?.unresolvedRolledBackMigrationRows == null
|
||||
? applyPlan.migrationHistory?.rolledBackMigrationRows
|
||||
: applyPlan.migrationHistory?.unresolvedRolledBackMigrationRows
|
||||
return {
|
||||
mode: applyPlan.mode || '',
|
||||
dryRun: applyPlan.dryRun !== false,
|
||||
@ -924,7 +928,7 @@ function buildFoundationRequiredMigrationApplyPlanSummary(applyPlan) {
|
||||
migrationHistoryReady:
|
||||
applyPlan.migrationHistory?.tableExists === true &&
|
||||
applyPlan.migrationHistory?.unfinishedMigrationRows === 0 &&
|
||||
applyPlan.migrationHistory?.rolledBackMigrationRows === 0,
|
||||
unresolvedRolledBackMigrationRows === 0,
|
||||
blockerKeys: Array.isArray(applyPlan.blockers)
|
||||
? applyPlan.blockers.map((blocker) => blocker.key).filter(Boolean)
|
||||
: [],
|
||||
|
||||
@ -23,6 +23,8 @@ function readiness(overrides = {}) {
|
||||
appliedMigrationRows: 86,
|
||||
unfinishedMigrationRows: 0,
|
||||
rolledBackMigrationRows: 0,
|
||||
resolvedRolledBackMigrationRows: 0,
|
||||
unresolvedRolledBackMigrationRows: 0,
|
||||
},
|
||||
migrationCount: 43,
|
||||
readyMigrationCount: 11,
|
||||
@ -77,15 +79,33 @@ describe('apply-master-data-foundation-migrations', () => {
|
||||
|
||||
it('requires clean Prisma migration history before applying foundation guards', () => {
|
||||
expect(migrationHistoryReady(readiness().migrationHistory)).toBe(true)
|
||||
expect(migrationHistoryReady({
|
||||
tableExists: true,
|
||||
unfinishedMigrationRows: 0,
|
||||
rolledBackMigrationRows: 11,
|
||||
resolvedRolledBackMigrationRows: 11,
|
||||
unresolvedRolledBackMigrationRows: 0,
|
||||
})).toBe(true)
|
||||
expect(migrationHistoryReady({
|
||||
tableExists: false,
|
||||
unfinishedMigrationRows: 0,
|
||||
rolledBackMigrationRows: 0,
|
||||
resolvedRolledBackMigrationRows: 0,
|
||||
unresolvedRolledBackMigrationRows: 0,
|
||||
})).toBe(false)
|
||||
expect(migrationHistoryReady({
|
||||
tableExists: true,
|
||||
unfinishedMigrationRows: 1,
|
||||
rolledBackMigrationRows: 0,
|
||||
resolvedRolledBackMigrationRows: 0,
|
||||
unresolvedRolledBackMigrationRows: 0,
|
||||
})).toBe(false)
|
||||
expect(migrationHistoryReady({
|
||||
tableExists: true,
|
||||
unfinishedMigrationRows: 0,
|
||||
rolledBackMigrationRows: 11,
|
||||
resolvedRolledBackMigrationRows: 10,
|
||||
unresolvedRolledBackMigrationRows: 1,
|
||||
})).toBe(false)
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user