Liquibase for multiple databases

I have already implemented Liquibase with Maven. We are currently using a single database (db2), but now we need to add a new database to the application, which will have different objects.

I saw that I can define a new profile in maven, but I could not learn how to distinguish which objects are created in which database.

Is there a solution? Can I support two different databases with different objects using Liquibase?

+4
source share
3 answers

You might want to have 2 separate change logs for managing two databases, even if they are both used by the same application.

+3
source

documentation, , :

<plugin>
  <groupId>org.liquibase</groupId>
  <artifactId>liquibase-maven-plugin</artifactId>
  <version>3.0.5</version>
  <executions>
    <execution>
      <phase>process-resources</phase>
      <configuration>
        <changeLogFile>PATH_TO_CHANGELOG_1</changeLogFile>
        ... connection properties  ...
      </configuration>
      <goals>
        <goal>update</goal>
      </goals>
    </execution>
   <execution>
      <phase>process-resources</phase>
      <configuration>
        <changeLogFile>PATH_TO_CHANGELOG_2</changeLogFile>
        ... connection properties  ...
      </configuration>
      <goals>
        <goal>update</goal>
      </goals>
    </execution>
  </executions>
</plugin>

, changelog.xml, .

, preconditions , , .

:

<changeSet id="1" author="bob">
    <preConditions onFail="MARK_RAN">
         <dbms type="oracle" />
    </preConditions>
    <comment>Comments should go after preCondition. If they are before then liquibase usually gives error.</comment>
    <dropTable tableName="oldtable"/>
</changeSet>

onFail="MARK_RAN" Liquibase , , . . customPrecondition documentation .

+1

, 2 , node .

                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>3.0.5</version>
                    <executions>
                        <execution>
                            <id>db1-update</id>
                            <phase>process-resources</phase>
                            <configuration>
                                <changeLogFile>src/main/resources/org/liquibase/db1.xml</changeLogFile>
                                <driver>org.postgresql.Driver</driver>
                                <url>jdbc:postgresql://localhost/db1</url>
                                <username>..</username>
                                <password>..</password>
                            </configuration>
                            <goals>
                                <goal>update</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>db2-update</id>
                            <phase>process-resources</phase>
                            <configuration>
                                <changeLogFile>src/main/resources/org/liquibase/db2.xml</changeLogFile>
                                <driver>org.postgresql.Driver</driver>
                                <url>jdbc:postgresql://localhost/db2</url>
                                <username>...</username>
                                <password>...</password>
                            </configuration>
                            <goals>
                                <goal>update</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>db3-update</id>
                            <phase>process-resources</phase>
                            <configuration>
                                <changeLogFile>src/main/resources/org/liquibase/db3.xml</changeLogFile>
                                <driver>org.postgresql.Driver</driver>
                                <url>jdbc:postgresql://localhost/db3</url>
                                <username>...</username>
                                <password>...</password>
                            </configuration>
                            <goals>
                                <goal>update</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
0
source

All Articles