Set up Liquibase for multiple environments

Last updated: July 14, 2025

In real-world projects, you’ll often work with several database environments, such as development, testing, staging, and production. Liquibase gives you tools to apply database changes safely and selectively across these environments. This article walks through how to use Liquibase contexts to manage multiple environments.

Before you begin

Procedure

1

Add context labels to your changesets

Liquibase contexts let you apply changesets conditionally depending on the environment.

You can define changesets with contexts like legacy and non-legacy. In the example code, the first changeset runs in the legacy environment, HR_Dev. The second changeset runs in the non-legacy environment, HR_Test.

Example Code
<changeSet id="1" author="liquibase" context="legacy">
  <createTable tableName="old_employee_data">
    <column name="emp_id" type="int" />
    <column name="name" type="varchar(100)" />
  </createTable>
</changeSet>
<changeSet id="2" author="liquibase" context="non-legacy">
  <createTable tableName="employee">
    <column name="id" type="int" />
    <column name="first_name" type="varchar(50)" />
    <column name="last_name" type="varchar(50)" />
  </createTable>
</changeSet>
2

Apply your changes.

To apply changes only for HR_Dev, run:

liquibase update --context-filter=legacy

To apply changes for HR_Test, run:

liquibase update --context-filter=non-legacy
Set up Liquibase for multiple environments - Liquibase