June 17, 2020
Customize generated SQL from an XML changeset
Sometimes you need to modify SQL in specific changesets and you still want to use the abstracting power of XML to make your change database agnostic. Although Liquibase supports most standard SQL statements with change types, there are situations when the generated SQL needs to be modified for your particular needs. To accommodate this, Liquibase offers a very useful tag: <modifySql>.
Scenario
You need to create a table using an XML changeset for a specific filegroup on SQL Server.
Problem: The XML changeset does not offer a filegroup attribute.
Solution: Use the handy <modifySql> tag!
Example
Let’s use the <modifySql> tag to append the string: “ON FileGroup_Name”.
Notice that the dbms=mssql attribute ensures that this <modifySql> tag will only apply to the SQL Server database platform.
Now you have generated a SQL statement that includes the table within the desired filegroup!
Simply run the liquibase updateSQL command to verify the generated SQL and conduct a quick code review.
Once the generated SQL is confirmed and is ready to be deployed, run the liquibase update command to apply the changes