Reputation: 1854
Is it possible to use some kind of variable or property to set the changeset author in a liquibase formatted sql file.
I have tried to set a property in a chnagelog.xml and using the property for the author as show below.
changelog.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<property name="author" value="my-author"/>
<include file="sql/test_schema.sql"/>
</databaseChangeLog>
And test_schemal.sql
--liquibase formatted sql
--changeset ${author}:1
CREATE SCHEMA IF NOT EXISTS test_schema;
--rollback DROP SCHEMA IF EXISTS test_schema;
However, the author is not set to the author property, "my-author".
I think this could also be done with terraform templating, but is there a way to do this using only liquibase functionality?
Upvotes: 1
Views: 5931
Reputation: 917
Liquibase allows dynamic substitution of properties in changelog files. We can configure multiple properties inside a file and then use them wherever required. In your case, we can just configure property "authorName" with some value and then use it in changelog file using ${authorName} syntax.
Whatever Jorge has mentioned in his answer is correct. Liquibase assigns or prioritizes value for configured property in below order:
You can do it as below example code snippet:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="${authorName}" id="some-unique-id" dbms="${dbType}" context="some-context">
**My SQL query/ transactional logic goes here**
</changeSet>
</databaseChangeLog>
In liquibase.properties file, I will configure these properties as follows:
authorName=Rakhi
dbType=PostgreSQL
Note: above example is using 2 properties (authorName and dbType). You can use only authorName or even more than that.
If you need help with creating "liquibase.properties" file, visit this link
Cheers!
Upvotes: 2
Reputation: 186
Using property substitution in your changelog
Liquibase allows you to use different ways to can set property values. Liquibase assigns these values in the order specified below:
As an attribute passed to your Liquibase runner.
Check this liquibase doc
Upvotes: 1