liquibase / liquibase-postgresql

Liquibase Postgres Extension
29 stars 19 forks source link

Checksum differs when running from Liquibase maven plugin and SpringLiquibase #1

Open bvlangen opened 9 years ago

bvlangen commented 9 years ago

I'm using Liquibase to update my database from two sides:

  1. Via the Liquibase Maven plugin
  2. Via Spring with SpringLiquibase that updates the database upon application startup

Running vacuum from the db-changelog-master.xml like the following code snippet works for now. (By setting validCheckSum to ANY. But without it database updates only succeed when run from one of the two sides described above. F.i. when it has run via SpringLiquibase, and is run again via SpringLiquibase, all is fine. Checksum is ok. But when I then update the database via Maven a checksum error occurs. The checksum is different when run from Maven then when run from SpringLiquibase.

Maybe it has something do with logicalFilePath. Without it, it seems to run ok, but then I run into other issues with Spring filename path using classpath:... etc..

Using: Java 7, Postgresql 9.4 with postgis, Spring 4.1.6, Liquibase 3.3.3, Liquibase-spacial 1.2.1, liquibase-postgresql 3.0

Note: Same checksum error occurs when using another extension, liquibase-spatial. With this extension specifically on the creation of a spatial index. See https://github.com/lonnyj/liquibase-spatial/issues/7

File db-changelog-master.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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.3.xsd
                            http://www.liquibase.org/xml/ns/dbchangelog-ext
                            http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"
        logicalFilePath="db-changelog-master.xml">

    <include file="db-changelog-initial-schema-1.0.xml" relativeToChangelogFile="true"/>
    <include file="db-changelog-sprint-x.xml" relativeToChangelogFile="true"/>
    <include file="db-changelog-spacial-example.xml" relativeToChangelogFile="true"/>

    <changeSet id="maintenance: vacuum postgres" author="bvlangen" runInTransaction="false" runAlways="true">
        <!-- Checksum differs when run from Maven or Spring, therefore set to valid ANY -->
        <validCheckSum>ANY</validCheckSum>
        <comment>Vacuum the PostgreSQL database</comment>
        <ext:vacuum/>
    </changeSet>

</databaseChangeLog>

Spring config:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <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="defaultSchema" value="${jdbc.defaultSchema}" />
    </bean>
</beans>

Snippet db-changelog-spacial-example.xml:

    <changeSet id="Create spatial index" author="bvlangen">
        <!-- Checksum differs when run from Maven or Spring, therefore set to valid ANY and added precondition -->
        <validCheckSum>ANY</validCheckSum>
        <preConditions>
            <not>
                <spatial:spatialIndexExists tableName="EXAMPLE" columnNames="GEOM" />
            </not>
        </preConditions>
        <comment>Create spatial index</comment>
        <spatial:createSpatialIndex tableName="EXAMPLE" indexName="EXAMPLE_GEOM_IDX" geometryType="Point" srid="4326">
            <column name="GEOM" />
        </spatial:createSpatialIndex>
    </changeSet>

┆Issue is synchronized with this Jira Bug by Unito

Sintaksis13 commented 4 years ago

Faced the same problem but with gradle plugin (only several changeSets had problem)