Add tag to a specific changeSet in Liquidbase PRO with MongoDB

21 views Asked by At

I have

databaseChangeLog:
    - changeSet:
          id: add_game_interests
          author: tiago
          runWith: mongosh
          changes:
              - mongoFile:
                    dbms: mongodb
                    path: add_game_interests.js
                    relativeToChangelogFile: true
          rollback:
              - mongoFile:
                  dbms: mongodb
                  path: delete_game_interests.js
                  relativeToChangelogFile: true
          tagDatabase:
              - tag: 0.0.1

but getting

Caused by: liquibase.exception.LiquibaseException:
In changeset 'add_game_interests::tiago' there is an unsupported change type 'tagDatabase'.
A  changeset with runWith='mongosh' attribute may only contain mongo or mongoFile change types. Learn more at https://docs.liquibase.com
        at liquibase.changelog.ChangeLogIterator.validateChangeSetExecutor(ChangeLogIterator.java:193)
        at liquibase.changelog.ChangeLogIterator$2.lambda$run$0(ChangeLogIterator.java:129)
        at liquibase.Scope.lambda$child$0(Scope.java:186)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:185)
        at liquibase.Scope.child(Scope.java:164)
        at liquibase.changelog.ChangeLogIterator$2.run(ChangeLogIterator.java:122)
        at liquibase.Scope.lambda$child$0(Scope.java:186)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:185)
        at liquibase.Scope.child(Scope.java:164)
        at liquibase.Scope.child(Scope.java:252)
        at liquibase.Scope.child(Scope.java:256)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:89)
        ... 26 more

Then tried

databaseChangeLog:
    - changeSet:
          id: add_game_interests
          author: tiago
          runWith: mongosh
          changes:
              - mongoFile:
                    dbms: mongodb
                    path: add_game_interests.js
                    relativeToChangelogFile: true
          rollback:
              - mongoFile:
                  dbms: mongodb
                  path: delete_game_interests.js
                  relativeToChangelogFile: true
    - changeSet:
          id: add_game_interests_tag
          author: tiago
          tagDatabase:
              - tag: 0.0.1

while that adds the tag, it doesn't add the tag to the previous one with id add_game_interests

enter image description here

1

There are 1 answers

2
Alexander Pletnev On BEST ANSWER

while that adds the tag, it doesn't add the tag to the previous one with id add_game_interests

And it shouldn't. tagDatabase is a separate change type and it applies a tag to the current schema state, not to a particular changeset:

You can typically use the tagDatabase Change Type when you want to tag your current database state, release, or version, and then deploy new changesets to that tag or roll back changesets applied after that tag.

Moreover, there is a specific note in the documentation that emphasizes that it should not be used like in your example:

Note: The XSD doesn't allow the tagDatabase Change Type to be used with another Change Types in the same changeset.

This is because of the following, and how Liquibase works in general:

If you deploy a tagDatabase changeset from your changelog, it adds a new row to the DATABASECHANGELOG table. This row will have the tag name specified in that changeset.