0

My requirement is as follows

  1. As i run demo.sql file using the Liquibase. It consist of the 10 sql statements.
  2. At the 5th statement if it encounters error, it should completely roll back all the changes.

  3. My requirement is to continue it till finishes the script and try to commit the rest statements which are valid.

Any solution on that?

Kris Rice
  • 3,300
  • 15
  • 33
Abhishek
  • 101
  • 3
  • 8
  • 1
    Wanted to run scrip inspite of faiure of one sql statemet !!! – Abhishek May 24 '18 at 06:08
  • Basically i Wanted to contineu execution of scrip even one out of 10 statement is error prone if one statement in the file got error it should skip that one but rest should be executed Is this possible using liquibase Note: I wnt to execute one sql file as one transaction i.e in one changeset only . thanks if there is any way please suggest – Abhishek May 25 '18 at 13:17

2 Answers2

1

You could also separate it out into 10 changesets, e.g.

<changeSet author="liquibase-docs" id="sql-example" failOnError="false">
  <sql>SELECT * from one_table;</sql>
</changeSet>
<changeSet author="liquibase-docs" id="sql-example2" failOnError="false">
  <sql>SELECT * from another_table;</sql>
</changeSet>
serv-inc
  • 35,772
  • 9
  • 166
  • 188
0

You should add preConditions and rollback to you liquibase script.

From the https://www.liquibase.org/documentation/changes/sql_file.html

<changeSet author="liquibase-docs" id="sqlFile-example">
    <preConditions onFail="MARK_RAN">
         <!-- your preconditions here -->
    </preConditions>
    <sqlFile dbms="h2, oracle"
            encoding="utf8"
            endDelimiter="\nGO"
            path="my/path/file.sql"
            relativeToChangelogFile="true"
            splitStatements="true"
            stripComments="true"/>
    <rollback>
        <!-- your rollback here -->
    </rollback>
</changeSet>

If you want to rollback specifically on the 5th statement in demo.sql, then perhaps you can split your demo.sql into two files and execute them in separate changeSets: the first will include statements 1-5, and the second will include statements 6-10.

tcxbalage
  • 696
  • 1
  • 10
  • 30
htshame
  • 6,599
  • 5
  • 36
  • 56
  • thanks but wanted to contineu the script inspite of the error in one statement is there any way it should not rollback the whole changeset inspite of change!!! – Abhishek May 25 '18 at 13:27