Java.DBMigrationTools.What does runOnChange do?

Short Answer

runOnChange="true" tells Liquibase to re-run a changeset if its definition changes, even if it was already applied.

By default, Liquibase only runs each changeset once, but runOnChange forces Liquibase to track changes via checksums and re-apply the changeset if it detects any modifications.


🔎 Detailed Explanation

🔸 Without runOnChange

Liquibase stores a checksum for each applied changeset in the DATABASECHANGELOG table.

If the changeset is later modified, Liquibase will:

  • ❌ Detect a checksum mismatch
  • ❌ Throw a validation error
  • ✅ Require you to fix it manually or use clearCheckSums

This behavior prevents untracked schema drift.


🔸 With runOnChange="true"

If a changeset has:

<changeSet id="1" author="alice" runOnChange="true">
  <createView viewName="user_view" ... />
</changeSet>

Liquibase will:

  • Detect a checksum change
  • Re-execute the changeset automatically
  • ✅ Update the DATABASECHANGELOG record with the new checksum

🧠 Common Use Cases

Use CaseUse runOnChange?
Creating or modifying a view✅ Yes
Changing a stored procedure or trigger✅ Yes
Adding a comment or default value✅ Yes
Creating tables/columns❌ Usually no

⚠️ Caution

Use runOnChange carefully:

  • It re-applies changes each time the checksum changes — which can overwrite custom manual edits in prod
  • Not recommended for large data operations (e.g. insert or update)

📌 Key Takeaways

runOnChange="true" re-executes a changeset if it has been modified after execution
✅ Useful for views, procedures, and other objects that evolve over time
❌ Should be used with caution — especially in production environments

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