Reputation: 1985
I have prepared two different solutions to one issue. By solution I mean database triggers that call database procedures. I want that user/client be able to choose the solution he want to use because both solutions have advantages and disadvantages. I also want that user be able to change solution. These two solutions are mutually exclusive, in other words, user can use only one solution at a time.
I have three changelog files:
It is easy if user knows what solution he wants. He will execute liquibase update with proper solution file. Unfortunately I am not sure how to ensure that the user can change the solution at any time. Currently applied solution has to be removed or disabled before applying the new one. By removing or disabling solution I mean at least removing or disabling database triggers (procedures and tables also can be removed but it does not matter). User cannot execute liquibase dropAll because user does not want to lost any data stored in schema created by master.xml changelog.
Let's assume that user will choose soltion1 first, then he will change to solution2 and after that he will change again to solution1.
I have never used tag and rollback commands but I have read about it in documentation and have following idea. User first executes update command on master.xml. After that user has to create tag. Next user executes update command on soultion1.xml. To change solution user has to fist rollback to his tag and after that user executes update command on soultion2.xml. If user wants again change to solution1 then he has to first rollback to tag and execute update again on soultion1.xml.
I hope that my idea will work properly but I have not tested it so it is possible that it will not work. Unfortunately this solution has one big disadvantage, user has to remember to create tag. If user forgets to create tag he will be in trouble. User will have to count changesets and use rollbackCount command. Additionally triggers are created in sql tag in solutions1.xml and solutions2.xml files. I am afraid that rollback does not work properly with sql tag.
Is there any better solution?
Upvotes: 0
Views: 130
Reputation: 244
I think the solution that you described will work.
In order to not forget to create the tag you can add a changeset to each solution.xml that uses the "tagDatabase" change-type. Then the tag is created during the Liquibase update command.
https://docs.liquibase.com/change-types/community/tag-database.html
Since you are creating the triggers via custom sql then you will need to provide the rollback sql for those triggers via custom sql in a rollback block. See "rollback tag" section here:
https://docs.liquibase.com/concepts/basic/changeset.html
Upvotes: 1