Java.DBMigrationTools.How does Liquibase track which changes were applied?

Short Answer

Liquibase tracks applied changes by recording each successfully executed changeset in a special database table called DATABASECHANGELOG.
Each entry includes metadata like id, author, filename, checksum, and execution timestamp.


🔎 Detailed Explanation

When you run liquibase update, Liquibase:

  1. Reads your changelog file(s)
  2. For each <changeSet>:
    • Checks if it’s already listed in the DATABASECHANGELOG table
    • Compares the checksum to detect changes
  3. Executes the changeset only if it hasn’t been run yet, or if you’ve specified runAlways or runOnChange
  4. Records a new row in DATABASECHANGELOG after successful execution

📋 Key Columns in DATABASECHANGELOG

ColumnPurpose
IDThe unique ID from the changeset
AUTHORAuthor name from the changeset
FILENAMEChangelog file name where the changeset is defined
DATEEXECUTEDTimestamp when this changeset was run
ORDEREXECUTEDOrder of execution
MD5SUM (checksum)Verifies if the changeset content has been modified
EXECTYPEEXECUTED, FAILED, SKIPPED, etc.
DESCRIPTIONDescription of the change (optional)

🧠 Why is this important?

  • ✅ Ensures each changeset runs exactly once
  • ✅ Supports safe retries — rerunning update won’t re-apply executed changesets
  • ✅ Detects unauthorized or accidental modifications via checksum mismatch
  • ✅ Enables rollback, tagging, auditing, and repeatable deployments

🔄 Related Concepts

  • Checksum mismatch → means the changeset was edited after execution
  • clearCheckSums command → resets checksums if you deliberately modified a changeset and want Liquibase to accept the new version
  • runOnChange="true" → Liquibase re-applies the changeset if the checksum changes (use with caution)

📌 Key Takeaways

✅ Liquibase uses the DATABASECHANGELOG table to track exactly which changesets were applied, when, and in what order.
✅ This mechanism ensures idempotency, auditability, and integrity of schema changes across environments.
✅ You never need to manually track what’s been applied — Liquibase does it all.

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