Using liquibase file paths via both maven and spring

Alexandr picture Alexandr · May 17, 2013 · Viewed 14.1k times · Source

I update scheme and initial data in spring context using the following beean:

<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
    <property name="dataSource" ref="dataSource" />
    <property name="changeLog" value="classpath:db/changelog/db.changelog-master.xml" />
    <property name="dropFirst" value="true" />
</bean>

I also use Maven liquibase plugin to generate sql scripts in order to see what tables are created and etc.

 <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>2.0.5</version>
                <configuration>
                    <!--mvn initialize liquibase:updateSQL-->
                    <propertyFile>src/main/resources/db/config/liquibase-gensql-data-access.properties</propertyFile>
                    <changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>

                </configuration>
           </plugin>

The db.changelog-master.xml file includes child liquibase changelog files. The problem, how to refer to them from the master. When I use Spring I have to use the following path via classpath:

<include file="classpath:/db/changelog/db.changelog-1.0.xml"/>

When Maven is used, the path is:

<include file="src/main/resources/db/changelog/db.changelog-1.0.xml"/>

I'd like to have the same configuration for both cases. How can I archive it?

Answer

Igor Vash picture Igor Vash · Aug 29, 2013

I think if you change your Maven path from

<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>

to

<changeLogFile>db/changelog/db.changelog-master.xml</changeLogFile>

and update db.changelog-master.xml file for all included files to use path relative to src/main/resources directory, it will fix the problem.

I solved this problem by using the same path to changeLog files in Spring, maven and integration test which call Liquibase. All my changelog files are located under /src/main/resources/db directory in one of the Maven modules within a project.

Maven profile which runs Liquibase, notice path: db/masterChangeLog.xml

<plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>3.0.2</version>

                    <executions>
                        <execution>
                            <id>*** Install a last major release version of db ***</id>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>update</goal>
                            </goals>
                            <configuration>
                                <changeLogFile>db/masterChangeLog.xml</changeLogFile>
                                <contexts>dbBuildContext, dmlDevContext</contexts>
                                <propertyFile>db/liquibase-${user.name}.properties</propertyFile>
                                <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                                <logging>debug</logging>
                            </configuration>
                        </execution>

db/masterChangeLog.xml file includes these files:

<include file="db/install.xml"/>
<include file="db/update.xml"/>

db/install.xml file includes other changelog files (so does update.xml):

<includeAll path="db/install/seq"/>
<includeAll path="db/install/tab"/>
<includeAll path="db/install/cst"/>
<includeAll path="db/latest/vw"  />

Spring context executes the same set of db scripts upon app startup as follows:

<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
    <property name="dataSource" ref="baseCostManagementDataSource" />
    <property name="changeLog" value="classpath:db/masterChangelog.xml" />
    <property name="contexts" value="dbBuildContext, dmlDevContext" />
</bean>