TransWikia.com

liquibase roll back with spring boot

Stack Overflow Asked by user1999453 on October 7, 2020

I have a spring boot app(v2.3.3) which contains Liquidbase tool to create my table and initialise it.
When I start spring boos it is working fine, the tables are created and data inserted by using sql scripts and the Liquidbase configs are shown below:

application.yml:

spring:
  liquibase:
    change-log: classpath:db/db.master.xml

src/main/resources/db: db.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"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
    <includeAll path="scripts/" relativeToChangelogFile="true"/>`enter code here`

</databaseChangeLog>

src/main/resources/db/script/

  • 001.createTableAudit.sql
  • 002.insertDataTableAudit.sql

Let say I want to rollback 002.insertDataTableAudit.sql, is it possible rollback the insertDataTableAudit
when starting my Spring Boot App?

I know it can be done by maven : mvn liquibase:rollback but is it possible to acheive the same thing with Spring Boot?

Thanks in advance

One Answer

I don't think there's such functionality in spring boot out of the box. However you can create that functionality easily:

final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
final Liquibase liquibase = new Liquibase("changelogpath", new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), new FileSystemResourceAccessor()), database);
liquibase.rollback("TAG", (String) null);

Answered by bilak on October 7, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP