Using Liquibase to execute dynamic SQL queries with property files

Hi everyone,
I’ve recently started using Liquibase and so far, I’m impressed with it. Currently, I’m using it in formatted SQL mode (–liquibase formatted SQL), and it’s working great for me. However, I’ve been running into some issues when trying to execute INSERT queries where the values are not known at the time of code writing but only at deployment time.

To solve this problem, I created a properties file with two variables, and I’d like to use them through Liquibase’s API to execute a query like the following:

–changeset user1:4
–precondition (tableExists tableName: application_properties)
INSERT INTO application_properties (k, v) VALUES (${path}, ${nameDb});

The ‘path’ and ‘nameDb’ variables are retrieved from a properties file. I would really appreciate it if someone could help me understand how to achieve this. I’ve tried going through the documentation, but I haven’t been able to figure it out.

Thanks a lot!

Hi @codabat,

There’s an overview of substituting properties in the documentation here → Substituting Properties in Changelogs

How you set them will depend on how you are calling liquibase. There are different combinations based on what makes sense for you. For example, from the Liquibase CLI you would do the following:

-Dpath=my/path -DnameDb=myname

Does that help?

-PJ