Managing common SQL code in postgres database via liquibase

We are using SQL formatted changelogs. We have a sql file, create_db.sql for each postgres database managed via liquibase. We have few common tables for each database which is placed in a common.sql file.

It looks like include element can serve my purpose. But it does not work with SQL formatted changelogs.

One approach I can think of handling this case is to not have common.sql altogether and place all the common code in each create_db.sql as I could not find any good way of importing common.sql in each create_db.sql to be managed via liquibase using sql formatted changelogs. But this will cause a lot of code duplication.

Can someone suggest some other better way of managing the common.sql file also via liquibase for each postgres database?

Formatted SQL changelogs do work with the include tag, there is an example on the documentation page, and this is stated on the page:

“Your reference changelog can be SQL, XML, YAML, or JSON file types.”

Ok right. <include> tag cannot be used in an SQL formatted root changelog.

1 Like