Update-to-tag runs all changesets if tag not found

I’m testing the liquibase update-to-tag functionality. If I fat-finger the tag ID, it seems like the safe way for Liquibase to behave is to not make any changes. Instead, for me, it just runs all changesets and gives me the warning below. This seems unsafe:

$ liquibase updateToTag oops
...
WARNING:  The tag 'oops' was not found in the changelog 'changelog.yml'. All changesets in the changelog were deployed.
...

Is there an option to fail / not make any updates at all if a tag is not found?

Related, the tag-exists command will tell you if a tag exists or not, but does not produce a non-zero return value if the tag does not exist. For example, if tag 1.0.0 exists but 1.0.1 does not I still get a 0 return value:

$ liquibase tag-exists 1.0.0
Liquibase Open Source 4.25.0 by Liquibase
The tag '1.0.0' already exists in 'postgres@jdbc:postgresql://localhost:5432/postgres'.
Liquibase command 'tag-exists' was executed successfully.

$ echo $?
0

Example with a non-existing tag (1.0.1):

$ liquibase tag-exists 1.0.1
Liquibase Open Source 4.25.0 by Liquibase
The tag '1.0.1' does NOT exist in 'postgres@jdbc:postgresql://localhost:5432/postgres'.
Liquibase command 'tag-exists' was executed successfully.

$ echo $?
0

To easily add the Liquibase tag configuration to an automated build, it would be great for this command to return a non-zero result if the tag did not exist. Is there a way to do that? Or do we need to parse the Liquibase output from the tag-exists command to put it into an automated build workflow?

1 Like

What version of Liquibase are you running?

I’m using Liquibase 4.25.0.

This behaviour has stayed the same using 4.28.

@mike.lee Did you find a workaround? I need a programmatic approach to check if a tag exists, for implementing automatic rollbacks.

I guess I could always query the changelogs table manually, still it would be great if one could use the official liquibase image in an init-container to get this information.

Then the init container could decide about the DB state, including rollbacks.

I ran my own test of “update-to-tag foo” where the tag “foo” doesn’t exist. This message was written to the output:

[2024-07-17 13:06:09] WARNING [liquibase.command] The tag ‘foo’ was not found in the changelog ‘db-changelog-master.xml’. All changesets in the changelog were deployed.

So I have to assume the behavior is intentional.

I did find this in the documentation, which was very interesting:

The update-to-tag command will deploy changes only when you have tagDatabase Change Type in your changelog file. You cannot use the update-to-tag command with the reference to a tag created in the DATABASECHANGELOG table using the tag command.

We ended up writing a custom Liquibase extension to validate whether the tag exists in an upcoming changeset, and then failing our builds if it doesn’t. I also went onto the Liquibase Discord and asked, and they said that that this functionality was something they’re intending on adding, but don’t know its priority.

You could also open a github issue.

To follow-up on this, we have opened a GitHub issue to fix this issue: update-to-tag runs even when provided tag doesn't exist · Issue #6126 · liquibase/liquibase · GitHub

1 Like