Liquibase is a database migration tool that Spring Boot configures automatically when liquibase-core is on the classpath. At startup it reads a changelog file, compares it with the DATABASECHANGELOG table, and runs only the changesets that have not been applied yet, so every environment ends up with the same schema.
Spring Boot runs Liquibase before the JPA EntityManagerFactory is used, which means your entities see a fully migrated schema. This guide covers how that works, how to configure it, and when to choose Liquibase over Flyway.
Without a migration tool, schema changes are applied by hand or by Hibernate's ddl-auto, which is unsafe for production because it cannot track history, handle data changes, or roll back. Liquibase replaces that with versioned, reviewable changes stored next to your code.
Each change is a changeset identified by the combination of id, author, and the changelog file path. Liquibase records every executed changeset, with an MD5 checksum, in two tables it creates itself:
| Table | Purpose |
|---|---|
DATABASECHANGELOG | One row per applied changeset, including checksum and execution time |
DATABASECHANGELOGLOCK | A lock so that only one application instance migrates at a time |
If someone edits an already applied changeset, the checksum no longer matches and Liquibase fails at startup. This protects you from silent drift between environments.
When org.liquibase:liquibase-core is a dependency and a DataSource is available, LiquibaseAutoConfiguration creates a SpringLiquibase bean and runs the migration during application startup.
Spring Boot manages the Liquibase version through its dependency BOM, so you normally omit the version. By default the master changelog is expected at classpath:/db/changelog/db.changelog-master.yaml. You can change that with a property.
Setting ddl-auto: validate (or none) is important. Liquibase owns the schema, and Hibernate should only verify that the entities match it.
Liquibase accepts XML, YAML, JSON and formatted SQL. YAML and XML are the most common. A good layout is one master file that includes one file per release or feature.
Prefer the built-in change types such as createTable and addColumn over raw SQL where you can, because Liquibase generates the right SQL for each database. Use the sql change type for vendor-specific statements and always supply a rollback block for those.
These three features control where and when a changeset runs.
context: test for seed data. Spring Boot activates them with spring.liquibase.contexts.spring.liquibase.labels.onFail.During normal operation you do nothing: start the application and pending changesets run. The log shows each executed changeset at startup.
Spring Boot does not expose rollback through properties. To roll back, use the Liquibase CLI, the Maven or Gradle plugin, or an update run from a deployment job. For example, liquibase rollback-count 1 reverts the latest changeset using its rollback block.
For production, many teams disable automatic migration in the application and run Liquibase as a separate step in the deployment pipeline. That avoids long migrations blocking startup and gives the application a database user with fewer privileges. You can also give Liquibase its own credentials with spring.liquibase.url, spring.liquibase.user and spring.liquibase.password.
Both tools are supported by Spring Boot auto-configuration. Choose based on how your team prefers to write migrations.
| Aspect | Liquibase | Flyway |
|---|---|---|
| Migration format | XML, YAML, JSON or SQL changelog | Plain SQL (or Java) files |
| Database independence | Generates SQL per database | SQL written for one database |
| Rollback | Rollback blocks per changeset | Undo migrations in paid editions |
| Learning curve | Higher | Lower |
Flyway is simpler when your team is comfortable with SQL and uses a single database. Liquibase fits better when you target several databases or want structured, declarative changes.
Yes. If liquibase-core is on the classpath and a DataSource exists, Spring Boot runs the changelog at startup. Set spring.liquibase.enabled=false to turn it off.
It looks for classpath:/db/changelog/db.changelog-master.yaml. Use spring.liquibase.change-log to point to another file, including an XML one.
You should not let both modify the schema. Let Liquibase manage it and set spring.jpa.hibernate.ddl-auto to validate or none.
Liquibase detects the checksum change and stops with a validation error. Add a new changeset instead of editing an applied one.
Liquibase gives a Spring Boot application versioned, repeatable and auditable schema changes. Spring Boot wires it in automatically, runs pending changesets before JPA starts, and lets you configure the changelog path, contexts and credentials through spring.liquibase.*. Keep changesets immutable, write rollback blocks, let Hibernate only validate, and consider running migrations from the pipeline in production.