Running a custom drop-first script with Liquibase

Viewed 1887

We want to drop all content of a schema and recreate the schema objects from a Liquibase change log in one of our automated test environments. Since we are using Oracle with partition-by-reference we run into Liquibase dropAll fails when there are reference partitioned tables but regardless of that we will not be able to rely on Liquibase dropAll anyway because we will be using other Oracle-specific objects.

We have tried using a change set like this (first among the change sets):

<changeSet author="foo" id="drop-schema" context="drop-first" runAlways="true">
  <validCheckSum>ANY</validCheckSum>
  <sqlFile path="classpath:/db/drop-schema.sql" splitStatements="true" stripComments="true" endDelimiter="/"/>
</changeSet>

... with a script that also empties the DATABASECHANGELOG table, but that only works every second time as the execution is actually part of the change set and not run before migration but during.

We do not want to resort to the solution of writing a Liquibase extension as suggested in Liquibase drop all functions - postgresql.

How can we have our script run before Liquibase migration in one of our environments as part of the spring boot startup? We are glancing towards Flyway instead which has built-in support for Callbacks where beforeMigrate looks like what we need...

0 Answers
Related