"how to tag a changeset in liquibase to rollback" Code Answer

5

rollback tags are designed to checkpoint your database's configuration.

the following commands will roll the database configuration back by 3 changesets and create a tag called "checkpoint":

mvn liquibase:rollback -dliquibase.rollbackcount=3
mvn liquibase:tag -dliquibase.tag=checkpoint

you can now update the database, and at any stage rollback to that point using the rollback tag:

mvn liquibase:rollback -dliquibase.rollbacktag=checkpoint

or alternatively generate the rollback sql:

mvn liquibase:rollbacksql -dliquibase.rollbacktag=checkpoint

revised example

i initially found it difficult to figure out how to configure the liquibase maven plugin. just in case it helps here's the example i've used.

the liquibase update is configured to run automatically, followed by tagging the database at the current maven revision number.

<project>
    <modelversion>4.0.0</modelversion>
    <groupid>com.myspotontheweb.db</groupid>
    <artifactid>liquibase-demo</artifactid>
    <version>1.0-snapshot</version>
    <properties>
        <!-- liquibase settings -->
        <liquibase.url>jdbc:h2:target/db1/liquibasetest;auto_server=true</liquibase.url>
        <liquibase.driver>org.h2.driver</liquibase.driver>
        <liquibase.username>user</liquibase.username>
        <liquibase.password>pass</liquibase.password>
        <liquibase.changelogfile>com/myspotontheweb/db/changelog/db-changelog-master.xml</liquibase.changelogfile>
        <liquibase.promptonnonlocaldatabase>false</liquibase.promptonnonlocaldatabase>
    </properties>
    <dependencies>
        <dependency>
            <groupid>com.h2database</groupid>
            <artifactid>h2</artifactid>
            <version>1.3.162</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>dbupdate</id>
            <activation>
                <activebydefault>true</activebydefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupid>org.liquibase</groupid>
                        <artifactid>liquibase-maven-plugin</artifactid>
                        <version>2.0.2</version>
                        <executions>
                            <execution>
                                <phase>process-resources</phase>
                                <configuration>
                                    <tag>${project.version}</tag>
                                </configuration>
                                <goals>
                                    <goal>update</goal>
                                    <goal>tag</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

liquibase is now configured as part of the standard life-cycle so can be run as follows:

mvn clean compile
By dau_sama on April 5 2022

Answers related to “how to tag a changeset in liquibase to rollback”

Only authorized users can answer the Search term. Please sign in first, or register a free account.