Java.DBMigrationTools.How do you apply a Liquibase migration from the command line?

Short Answer

You apply a Liquibase migration using the update command from the CLI:

liquibase update

This command tells Liquibase to:

  • Connect to your database
  • Read the changelog file
  • Apply any changesets that haven’t been run yet

🔎 Step-by-Step Command Line Usage

1. ✅ Basic Example

liquibase \
  --changeLogFile=db/changelog.xml \
  --url=jdbc:postgresql://localhost:5432/mydb \
  --username=myuser \
  --password=mypass \
  update

This runs all unapplied changesets in changelog.xml.

2. ✅ Set Configuration Once (Optional)

Create a liquibase.properties file to avoid typing all parameters every time:

changeLogFile=db/changelog.xml
url=jdbc:postgresql://localhost:5432/mydb
username=myuser
password=mypass
driver=org.postgresql.Driver

Then you can run:

liquibase update

Other Useful CLI Commands

CommandDescription
updateApply pending changesets
updateCount 1Apply only the next 1 changeset
updateSQLShow the SQL that would be executed
statusShow which changesets have not been applied
rollbackCount 1Roll back the last 1 changeset
tag my-release-v1Mark current DB state with a version tag
historyShow execution history of applied changes
clearCheckSumsClear checksums if you edited a changeset

🧠 Behind the scenes

  • Liquibase checks the DATABASECHANGELOG table
  • Compares changesets against what’s already been applied
  • Runs only new changesets (unless runAlways or runOnChange is used)

📌 Key Takeaways

✅ Use the update command to apply migrations via the command line
✅ Prefer using a liquibase.properties file for reusability
✅ Useful for local dev, automation, or CI/CD pipelines
✅ Track progress and debug with commands like status, history, and updateSQL

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