Java.DBMigrationTools.Explain when rollback happens in liquibase, when this event fired ?

Short Answer

Liquibase doesn’t automatically rollback on failure.
Rollback only happens when you explicitly run a rollback command — it’s a manual action you control.

🔎 When does rollback happen in Liquibase?

ScenarioDoes rollback happen automatically?Explanation
❌ A migration fails during update❌ NoLiquibase stops, but doesn’t rollback. You must fix the problem manually.
✅ You run liquibase rollback manually✅ YesLiquibase executes defined rollback logic.
✅ You run rollbackToTag, rollbackCount, or rollbackToDate✅ YesThese commands tell Liquibase which changes to reverse.

🔎 Examples of rollback commands

  • liquibase rollbackCount 2
    → Rolls back the last 2 changesets.
  • liquibase rollbackToTag release_1_0
    → Rolls back everything applied after that tag.
  • liquibase rollbackToDate 2025-07-01T10:00:00
    → Rolls back to schema state before that time.
  • liquibase rollbackSql
    → Generates the SQL that would be used during rollback (great for review).

❗ Important: rollback ≠ automatic error recovery

Liquibase doesn’t do rollback like a DB transaction would. If a changeset fails:

  • The DB may be left in a partial state
  • You need to fix the schema manually or run rollback yourself

That’s why:
✅ Keep each changeset small and isolated
✅ Always define a rollback clause for critical changes
✅ Test rollback in staging

📌 Key Takeaways

✅ Rollback in Liquibase only happens when explicitly invoked — it’s a manual operation.
❌ Rollback does not happen automatically on failure.
✅ Use rollback, rollbackCount, rollbackToTag, or rollbackToDate to reverse changes safely.
✅ Always test and define rollback logic in your changesets.

This entry was posted in Без рубрики. Bookmark the permalink.