fix: resequence existing workbench trace migration

This commit is contained in:
lyon
2026-06-20 20:37:08 +08:00
parent 971922be47
commit 183cf653f4
4 changed files with 132 additions and 22 deletions
+35 -5
View File
@@ -299,11 +299,7 @@ async function applyMigration(report, sql, env, options) {
} catch (error) {
await rollbackQuietly(client);
const classified = classifyMigrationError(error);
addBlocker(report, "runtime_blocker", blockerScope(classified.blocker), classified.summary, {
blocker: classified.blocker,
errorCode: classified.errorCode,
secretValuesPrinted: false
});
addBlocker(report, "runtime_blocker", blockerScope(classified.blocker), classified.summary, migrationErrorEvidence(classified));
} finally {
await closeClient();
}
@@ -586,8 +582,10 @@ function blockerScope(blocker) {
function classifyMigrationError(error) {
const errorCode = typeof error?.code === "string" ? error.code : "UNKNOWN";
const details = migrationErrorDetails(error);
if (errorCode === "HWLAB_PG_DRIVER_MISSING") {
return {
...details,
blocker: RUNTIME_DURABLE_ADAPTER_DRIVER_MISSING,
errorCode,
summary: "Postgres driver is unavailable for DEV runtime migration apply."
@@ -595,6 +593,7 @@ function classifyMigrationError(error) {
}
if (isMigrationSslError(error)) {
return {
...details,
blocker: RUNTIME_DURABLE_ADAPTER_SSL_BLOCKED,
errorCode,
summary: "DEV runtime migration reached Postgres, but SSL negotiation or SSL mode compatibility blocked apply."
@@ -602,6 +601,7 @@ function classifyMigrationError(error) {
}
if (["28P01", "28000", "42501"].includes(errorCode)) {
return {
...details,
blocker: RUNTIME_DURABLE_ADAPTER_AUTH_BLOCKED,
errorCode,
summary: "DEV runtime migration reached Postgres but auth or authorization blocked apply."
@@ -609,18 +609,48 @@ function classifyMigrationError(error) {
}
if (["42P01", "42703", "3F000"].includes(errorCode)) {
return {
...details,
blocker: RUNTIME_DURABLE_ADAPTER_SCHEMA_BLOCKED,
errorCode,
summary: "DEV runtime migration apply was blocked by schema/search_path state."
};
}
return {
...details,
blocker: RUNTIME_DURABLE_ADAPTER_QUERY_BLOCKED,
errorCode,
summary: "DEV runtime migration apply could not complete."
};
}
function migrationErrorEvidence(classified) {
return {
blocker: classified.blocker,
errorCode: classified.errorCode,
...(classified.errorConstraint ? { errorConstraint: classified.errorConstraint } : {}),
...(classified.errorTable ? { errorTable: classified.errorTable } : {}),
...(classified.errorMessage ? { errorMessage: classified.errorMessage } : {}),
...(classified.errorDetail ? { errorDetail: classified.errorDetail } : {}),
secretValuesPrinted: false
};
}
function migrationErrorDetails(error) {
return {
errorMessage: safeDiagnosticText(error?.message, 500),
errorDetail: safeDiagnosticText(error?.detail, 500),
errorConstraint: safeDiagnosticText(error?.constraint, 160),
errorTable: safeDiagnosticText(error?.table, 160)
};
}
function safeDiagnosticText(value, maxLength) {
if (typeof value !== "string") return null;
const redacted = redactFailureText(value).trim();
if (!redacted) return null;
return redacted.length > maxLength ? `${redacted.slice(0, maxLength)}...` : redacted;
}
function isMigrationSslError(error) {
const errorCode = typeof error?.code === "string" ? error.code : "";
if (errorCode.startsWith("ERR_SSL") || errorCode.startsWith("ERR_TLS")) {