Liquibase® version 3.8.5 is now available! Get it for free.
2018 XML Announcement
News All Previous Posts >>

Subscribe for email updates

- and/or -

Change Log Parameters

Since Liquibase 1.7

Liquibase allows dynamic substitution of parameters in a changelog. The parameters to replace are described using the ${parameter-name} syntax.

Configuring parameter values

Parameter values are looked up in the following order:

  1. Passed as a parameter to your Liquibase runner (see Ant, Maven, Servlet listener) etc. documentation for how to pass them)
  2. As a JVM system property
  3. As an environment variable
  4. command_line parameter if executed from the command line
  5. properties file if used or executed from the command line
  6. In the parameters block (property element) of the DatabaseChangeLog file itself

Once a parameter its value cannot be changed, only the first definition is used, other are skipped.

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <property name="clob.type" value="clob" dbms="oracle,postgresql"/>
    <property name="clob.type" value="longtext" dbms="mysql"/>
    <property name="table.name" value="tableA"/>

    <changeSet id="1" author="joe">
         <createTable tableName="${table.name}">
             <column name="id" type="int"/>
             <column name="${column1.name}" type="${clob.type}"/>
             <column name="${column2.name}" type="int"/>
         </createTable>
    </changeSet>
</databaseChangeLog>
databaseChangeLog:
  - property:
      dbms: oracle,postgresql
      name: clob.type
      value: clob
  - property:
      dbms: mysql
      name: clob.type
      value: longtext
  - property:
      name: table.name
      value: tableA
  - changeSet:
      id: 1
      author: joe
      changes:
      - createTable:
          tableName: ${table.name}
          columns:
          - column:
              name: id
              type: int
          - column:
              name: ${column1.name}
              type: "${clob.type}
              defaultValue: a string with an ${undefined.param} param against ${dbNote}
          - column:
              name: ${column2.name}
              type: int

<property>

Defines a parameter for the changelog. Given a list of contexts and/or databases, the parameter will be only used in those contexts and/or databases.

Available Attributes

AttributeDescription
nameName of the parameter. Required if file is not set
valueValue of the of the property. required if file is not set
fileName of the file the properties shall be loaded from. It will create a property for all properties in the file. The content of the file has to follow the java properties file format
contextContexts the property is valid in. Expected as comma separated list.
dbmsThe type of a database which that property is to be used. When the migration step is running, it checks the database type against this attribute. Valid database type names are listed on the supported databases page. It is possible to list multiple databases separated by commas. You can also specify that a changeset is NOT applicable to a particular database type by prefixing with !. The keywords all and none are also available.
globalboolean Defines whether the property is global or limited to the actual databaseChangeLog. Given as "true" or "false".

Examples:

    <property name="simpleproperty" value="somevalue"/>
    <property name="clob.type" value="clob" dbms="oracle,h2"/>
    <property name="clob.type" value="longtext" dbms="mysql"/>
    <property name="myproperty" value="yes" context="common,test"/>
    <property name="localproperty" value="foo" global="false"/>