How to make a liquibase migration fail when the executeCommand script fails?

Viewed 149

I'm doing some logic during the migration that requires running a custom script. To do this I'm using exexuteCommand to run a sh script which then runs my code using node. This works fine except that I can't actually make it so that the migration fails when an error occurs.

I've reduced the problem to the following example.

yaml file configuring the migration step:

databaseChangeLog:
  - changeSet:
      id:  1637655796
      author:  [me]
      changes:
        -  executeCommand:
             executable:  [path to script]

sh file:

node [path to .js file]

js file:

process.exit(1)

also tried:

throw new Error()

The file runs properly but liquibase marks the migration as successfull and updates the DB change log as if everything went as planned. How do I make the migration fail when the script fails?

1 Answers

I figured it out, even though the node script is failing in this example, the bash script isn't. I assumed that the failure "transfers" up the chain, but it doesn't. Doing exit 1 in the bash script results in the intended behavior.

To actually transfer the error from the node script to the bash script I used:

node [path to js file]
exit_code = $?
exit $exit_code

I could have skipped the 2nd line and wrote exit $? but my actual implementation has steps in between the js file running and the sh script exiting so the value of $? would have changed by then.

Related