Using profiles in liquibase
Asked Answered
O

4

8

I am using Liquibase and would like to execute the same script in two different variants (production and tests):

<changeSet author="..." id="...">   
    <insert tableName="...">
            <column name="ACTIVE" value="${isActive}" />
    </insert>
</changeset>

Currently, I use a property to steer this in two files:

<!--File1: For production --> 
<property name="isActive" value="true"/>

<!--File2: For tests--> 
<property name="isActive" value="false"/>

Is there a way to use something like a profile (as in Maven) or use command line arguments in Liquibase? I would like to avoid the handling of two different files, one for the production and one for the test systems.

Our answered 11/11, 2015 at 7:53 Comment(0)
D
11

You may specify context parameter for property or changeSet itself:

<property name="isActive" value="true" context="prod"/>
<property name="isActive" value="false" context="test"/>

Then pass the context parameter to liquibase in some way:

mvn liquibase:migrate -Dliquibase.contexts=prod
Detrital answered 16/11, 2015 at 23:41 Comment(0)
S
2

I know the post is old but I found a cleaner way using maven profiles directly. (Since you were asking to use maven profiles). You can use the liquibase.properties file and use the "parameter" properties of liquibase to access the variable from your changelog. Lets say you use the maven profile "prod", then you include the following to the liquibase-prod.properties:

parameter.isActive=true

Now you can simply call:

mvn -Pprod liquibase:update

Then it will replace automatically the ${isActive} variable that you put into your changelog:

<property name="isActive" value="${isActive}"></property>
Saval answered 2/12, 2021 at 18:18 Comment(0)
U
1

If you using cmd or terminal then use :

--contexts=prod
Uncial answered 10/8, 2018 at 9:27 Comment(0)
R
1

For me this setting of profiles in pom.xml was inspiring:

<profiles>
    <profile>
        <id>db-diff</id>
        <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-antrun-plugin</artifactId>
                  ...some profile db-diff settings like url, username password...
  </profile>
  <profile>
      <id>db-update</id>
      <build>
          <plugins>
              <plugin>
                  <groupId>org.liquibase</groupId>
                  <artifactId>liquibase-maven-plugin</artifactId>
                  ...some profile db-update settings like url, username, password...
  </profile>

using for example profile db-update for update:

mvn liquibase:update -Pdb-update
Recline answered 30/12, 2022 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.