Some of my tables implement concepts that need certain columns. I want to avoid having to copy the changesets for those columns to all relevant tables and would instead rather reuse a template to create the actual changesets.
Based on different ideas I found on the net I tried this:
db/templates/0004-create-validity-period-data-template.xml
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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.5.xsd">
<include file="../templates/0002-create-versioned-data-template.xml" relativeToChangelogFile="true" />
<changeSet author="${table.author}" id="Create ValidityPeriodData for ${table.name}" >
<comment>Create columns of super class ValidityPeriodData for table ${table.name}</comment>
<addColumn tableName="${table.name}" >
<column name="valid_from" type="date" remarks="the earliest point in time when this entry is valid" />
<column name="valid_until" type="date" remarks="the last point in time when this entry is valid" />
</addColumn>
</changeSet>
</databaseChangeLog>
db/changelog/0017-create-credential-table.xml
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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.5.xsd">
<property name="table.name" value="login" />
<property name="table.author" value="guess ;-)" />
<include file="../templates/0004-create-validity-period-data-template.xml" relativeToChangelogFile="true" />
<changeSet author="${table.author}" id="Create Credential table">
<addColumn tableName="${table.name}">
<column name="login_id" type="${uuid_type}"/>
<column name="password" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="salt" type="VARCHAR(128)"/>
</addColumn>
<addForeignKeyConstraint baseColumnNames="login_id"
baseTableName="${table.name}"
constraintName="fk_credential_of_login"
onDelete="RESTRICT"
onUpdate="RESTRICT"
referencedColumnNames="id"
referencedTableName="login"/>
</changeSet>
</databaseChangeLog>
The Problem
The properties (table.name, table.author) are by default global="true"
, which means they are visible in all changeset files, but they can not be overwritten/redefined. So this only works for a single table, which defeats the purpose.
If I declare them as global="false"
I can redefine them for every table that needs those columns, however now the included files do not see those properties.
The Question
Is there a way to redefine or overwrite properties for different changeset files (like what global="false"
does) but still have them behave like global="true"
in included files even recursively.