Alkis Kalogeris
Alkis Kalogeris

Reputation: 17745

liquibase maven plugin disable checksum

I'm using liquibase with maven-3. The first run works as expected. Consecutive runs though (even if the sql files contain changes) fail, as they are viewed as equivalent from liquibase and ignored (checksum).

All the sql actions in my sql scripts have taken into account the previous runs, so I don't want this behaviour. With this setup that you see below, how can I force liquibase to always execute my scripts, no matter the changes?

As you can see below I've already tried setting clearCheckSums as a goal and indeed it clears the hash values, but still no luck (thus commented out). This is the profile I've created

<profile>
    <id>liquibase-executions</id>
    <build>
        <defaultGoal>process-resources</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.4.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgres.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>update-schema</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>update</goal>
                            <!--<goal>clearCheckSums</goal>-->
                        </goals>
                        <configuration>
                            <driver>org.postgresql.Driver</driver>
                            <url>jdbc:postgresql://${db.url}</url>
                            <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                            <changeLogFile>${basedir}/src/main/resources/liquibase.sql</changeLogFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>update-data</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>update</goal>
                            <!--<goal>clearCheckSums</goal>-->
                        </goals>
                        <configuration>
                            <driver>org.postgresql.Driver</driver>
                            <url>jdbc:postgresql://${db.url}</url>
                            <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                            <changeLogFile>${basedir}/src/main/resources/liquibase-populate.sql</changeLogFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

And this is how I execute it

mvn process-resources -Pliquibase-executions -Ddb.url=POSTGRES_IP:5432/POSTGRES_DB -Dliquibase.username=POSTGRES_USERNAME

Upvotes: 2

Views: 1437

Answers (1)

msp
msp

Reputation: 3364

The Liquibase Maven plugin expects a changelog file, no plain .sql file. This file should contain your changeSets that you want Liquibase to execute. These changeSets can be instructed to be run every time you run Liquibase (by default they're only executed once). So there's no need to tamper with the checksum. For example your changelog file could look something like this:

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

    <changeSet id="your-id" author="msp" runAlways="true">
    ...
    </changeSet>
</databaseChangeLog>

The important part to achieve your intended behaviour is to set the runAlways="true" attribute in your liquibase changeset.

Upvotes: 1

Related Questions