1001Ferramentas
๐ŸŒŠ Generators

Liquibase Changelog Generator from Table

Generates a Liquibase changelog (YAML) with a createTable changeSet from a table name.

โ€”

Liquibase changelogs: abstract, portable database migrations

Liquibase is the database migration tool created by Nathan Voxland in 2006 and now maintained by Liquibase, Inc. Where Flyway tracks raw SQL files, Liquibase models each change as an abstract changeset in XML, YAML, JSON, or SQL. The runner translates the abstract description into dialect-specific SQL at execution time, which is what makes the same changelog work against PostgreSQL, MySQL, Oracle, SQL Server, Snowflake, and 50+ other engines.

Liquibase ships as an open-source CLI plus paid Liquibase Pro tier (advanced reports, Liquibase Flow pipelines) and the now-defunct Liquibase Hub (sunset in 2023). Integrations exist for Maven, Gradle, Spring Boot (spring-boot-starter-liquibase), Docker, Jenkins, GitHub Actions, and most CI systems.

Anatomy of a changeset

A changelog is a list of <changeSet> elements, each identified by an id + author pair. The XML form is the original; YAML is more readable and increasingly preferred:

<changeSet id="1" author="alice">
  <createTable tableName="users">
    <column name="id" type="uuid">
      <constraints primaryKey="true"/>
    </column>
    <column name="email" type="varchar(255)">
      <constraints unique="true" nullable="false"/>
    </column>
  </createTable>
</changeSet>

Liquibase converts type="uuid" to the appropriate dialect-specific column (UUID on PostgreSQL, CHAR(36) on MySQL, UNIQUEIDENTIFIER on SQL Server). You can still drop down to raw SQL with <sql> or <sqlFile path="..."/> when an abstraction is missing.

Rollback, contexts, labels, and preconditions

  • Rollback โ€” every changeset can declare an inverse via <rollback>. For known operations (createTable, addColumn) Liquibase generates the inverse automatically.
  • Contexts โ€” tag a changeset with context="dev,test" to only apply it in selected environments.
  • Labels โ€” similar to contexts but combined with boolean expressions for richer selection.
  • Preconditions โ€” gate execution on a check (<columnExists>, <sqlCheck>) so a changeset is skipped or fails fast when the DB is in an unexpected state.

Liquibase records applied changes in the DATABASECHANGELOG table (and locks the schema with DATABASECHANGELOGLOCK during runs to prevent concurrent migrations).

Liquibase vs Flyway

  • Abstraction โ€” Liquibase abstracts the dialect; Flyway is raw SQL. Pick Liquibase for true multi-database portability.
  • Rollback โ€” first-class in Liquibase open-source; only commercial in Flyway.
  • Verbosity โ€” Flyway is leaner; Liquibase YAML/XML carries metadata even for trivial changes.
  • Tooling โ€” both have strong Spring Boot, Maven, and CI integrations. Both can be driven from a Docker container.

Emerging alternatives in the 2023+ DevOps space include Atlas, Bytebase, and schema-as-code approaches that diff a desired-state file against the live database โ€” different philosophy, worth evaluating for greenfield projects.

FAQ

Should I use XML or YAML? YAML for readability and lower noise. XML is still common in legacy projects and tooling docs. JSON is rarely chosen.

Can I mix raw SQL in a YAML changelog? Yes โ€” use the sql change type or sqlFile to reference a separate file. Mix freely.

Liquibase or Flyway โ€” which should I pick? Liquibase if you target multiple databases or need built-in rollback. Flyway if your team prefers raw SQL and stays on one engine.

What happens if I edit a committed changeset? Liquibase recomputes the MD5 sum and refuses to run with a validation failed error. Add a new changeset with a new id instead.

Does Spring Boot integrate natively? Yes โ€” add spring-boot-starter-liquibase, place the changelog under src/main/resources/db/changelog/, and migrations run on startup.

Related Tools