MigrationFailedException thrown during partial rollback of a custom change in Liquibase
0 reputation · 22 Jan 2025, 19:06 UTC
0 reputation · 22 Jan 2025, 19:06 UTC
The goal is to clarify how Liquibase sequences custom changes—particularly Java code changesets and SQL changesets—when a rollback is interrupted before completion, and whether the thrown MigrationFailedException indicates which changeset was partially rolled back.
Because the framework does not explicitly document the ordering rule for mixed change types, the execution order may be ambiguous, and a partial rollback can leave the database in an inconsistent state, especially given potential differences between the open‑source and Pro editions and across version lines.
Key questions: How does Liquibase decide the execution order of a Java custom change relative to preceding SQL changesets? Does MigrationFailedException expose the specific changeset that experienced a partial rollback, and can any automatic compensation be triggered? Is this behavior stable between Liquibase 4.9.x and 5.x releases?
Liquibase executes changesets in the exact order they appear in the changelog file, regardless of whether the change is a standard SQL statement or a custom Java implementation. During a rollback, Liquibase processes these changesets in reverse chronological order based on their execution sequence.
If a custom Java changeset follows several SQL changesets in the changelog, the Java changeset will be the first to be rolled back. The framework does not prioritize change types; it strictly follows the stack (Last-In, First-Out) for rollbacks. If the custom Java rollback logic fails, the process halts immediately, and any preceding SQL changesets (which were deployed earlier) will remain in the database.
The MigrationFailedException is a generic wrapper. It does not inherently contain a dedicated field explicitly naming the "partially rolled back" changeset. Instead, you must rely on two primary diagnostic sources:
Liquibase does not provide automatic compensation for partial rollbacks. If a rollback fails, the database state depends entirely on the transactionality of your underlying database engine. If the database supports DDL transactions (e.g., PostgreSQL), the failed rollback may be atomic. If it does not (e.g., MySQL), you may be left in an inconsistent state requiring manual intervention.
The core sequencing logic—sequential execution and reverse rollback—is a fundamental architectural behavior and remains stable between Liquibase 4.9.x and 5.x. Differences between Open Source and Pro editions generally apply to deployment tooling and snapshots, not the execution order of mixed change types.
To identify the point of failure and verify state, use the following scoped approach:
SELECT id, author, filename FROM DATABASECHANGELOG ORDER BY dateexecuted DESC;
Identify the most recent changeset that was not removed during the rollback attempt.Required Diagnostic: To provide a more specific recovery path, please clarify if your database engine supports transactional DDL (e.g., PostgreSQL) or if it commits DDL changes immediately (e.g., MySQL/Oracle).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.