liquibase icon indicating copy to clipboard operation
liquibase copied to clipboard

rollbackOneChangeSet/rollbackOneUpdate breaks if changeLog with sqlFile changeSet not in the same command path

Open szandany opened this issue 5 years ago • 6 comments

Liquibase Version: Any Liquibase Version Liquibase Integration & Version CLI

Operating System Type & Version: Linux, Windows

Description

When using the following setup/conditions:

  1. rollbackOneChangeSet/rollbackOneUpdate commands
  2. changeLog with sqlFile changeSet/s
  3. The changeLog file is not in the same path from where the Liquibase command was executed

Liquibase cannot find the files referenced in the sqlFile changeSet.

For example:

Rolling Back Changeset:Users/support.liquibase.net/CLI-Projects/Postgres/1_dev/sqlFile_postgres_example/Q4/changeLogQ4.xml::plusOne4.sql::SteveZ
Unexpected error running Liquibase: liquibase.exception.DatabaseException: ERROR: could not find a function named "plusone4" [Failed SQL: (0) DROP FUNCTION plusone4]
For more information, please use the --logLevel flag

Steps To Reproduce

  1. Create a changeLog with sqlFile changeSets:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" 
xmlns:pro="http://www.liquibase.org/xml/ns/pro" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

  <changeSet author="SteveZ" id="exec_sales.sql" context="test" labels="pipeline1">
      <sqlFile dbms="postgresql"
              path="ddl/exec_sales.sql"
              relativeToChangelogFile="true"
              splitStatements="false"
              stripComments="true"/>
     <rollback>
       <sqlFile dbms="postgresql"
               path="ddl/dropExec_sales_rollback.sql"
               relativeToChangelogFile="true"
               splitStatements="false"
               stripComments="true"/>
     </rollback>
  </changeSet>
</databaseChangeLog>
  1. Place the changeLog somewhere above to path from where the liquibase command is going to run from.
  2. Run: liquibase update
  3. Run: liquibase history output should be:

- Database updated at <time> Applied 1 changeSet(s), DeploymentId: <deployment id>changeLog.xml::exec_sales.sql::SteveZ

  1. run: liquibase rollbackOneChangeSet --changeSetAuthor=<author> --changeSetId=<id> --changeSetPath=../<changelogFile> --force

Actual Behavior

Error: Liquibase Pro 4.0.0-beta1-DAT-4036-SNAPSHOT by Datical licensed to Liquibase Pro Customer until Tue Sep 22 19:00:00 CDT 2020 Starting Liquibase at 17:56:01 (version 4.0.0-beta1-DAT-4036-SNAPSHOT #25 built at 2020-04-13 20:26+0000) Unexpected error running Liquibase: liquibase.exception.UnexpectedLiquibaseException: java.io.IOException: File does not exist: 'ddl/exec_sales.sql'

Expected/Desired Behavior

The rollback should have been successful.

szandany avatar Apr 17 '20 22:04 szandany

➤ Mario Champion commented:

hey @szandany -- This is likely related to ResourceAccessor and either the changes in 4.0 or was always broken in previous versions in which the sqlFile points to non-same dirs. Can you test this with a 3.8.x version and see if the problem existed there and report back? thanks!

potentially related tickets: https://datical.atlassian.net/browse/DAT-4328 and https://datical.atlassian.net/browse/DAT-4327

jnewton03 avatar Apr 20 '20 14:04 jnewton03

Hi @mariochampion and @szandany . Where did this one end up?

molivasdat avatar Sep 26 '20 14:09 molivasdat

➤ Erzsebet Carmean commented:

Steve Z,

To work around this, you can add "C:// or /" to your classpath in the liquibase.properties file; this allows Liquibase to search from the root like it did pre-4.0.

Nathan Voxland and Mario Champion, does this require a fix or is the "fix" to update the classpath to invlude root?

CC :: Mike Olivas

sync-by-unito[bot] avatar Sep 29 '20 17:09 sync-by-unito[bot]

The Other issues: Other rollback commands like "rollback " or "rollbackCount " will rollback back the corresponding changeSets but the corresponding rows in the DATABASECHANGELOG will not be removed. should already be fixed in a previous release, so I'll take that section out and keep this ticket focused on the path handling.

nvoxland avatar Nov 17 '20 19:11 nvoxland

➤ Mario Champion commented:

good plan -- thanks!

This comment was left via Slack.

sync-by-unito[bot] avatar Nov 17 '20 19:11 sync-by-unito[bot]

I think this behavior is "by design". Liquibase looks up the changeSets to update, rollback, etc based partly on the "path" of the changeSet. That path needs to remain consistent every time you run liquibase, including in the rollbackOneChangeSet call.

The fact that you have a --changeSetPath=../<changelogFile> in the rollback command vs the update output of just changeLog.xml makes it look like you are referencing your changelog files differently at different times.

For sure, the --changeSetPath attribute is the path as saved in the databasechangelog table which I don't think can start with ../'s in them? The value you set for that should be the same as the path shown in the history output, which in your example is changeLog.xml

nvoxland avatar Nov 17 '20 19:11 nvoxland