Hello Steve,
many thanks for you quick response.
I am using right now the XML format.
Before going on for me it is not clear what you mean with:
"If
you intend to use the XML changelog format and enforce that all
changes to all database instances are made by developers/DBAs making
additions to the XML changelog"
Sounds
like you would recommend a different approach?
Back
to the previous question.
Here
our template table file:
000_DefaultTableTemplate.xml
- <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
- xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
- http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd
- http://www.liquibase.org/xml/ns/dbchangelog-ext
- http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
-
- <changeSet author="${table.author}" id="${changeset.name}_DefaultTable">
- <createTable schemaName="${table.schema}" tableName="${table.name}">
- <column name="id" type="int" remarks="surrogate key for the row" />
- <column name="uuid" type="uuid" remarks="additional surrogate key for the row, which ensures also uniqueness over mulitple database instances"/>
- <column name="rowCreatedUserId" type="${varchar50}" remarks="userId of the user who created this row"/>
- <column name="rowCreated" type="timestamp" remarks="insert timestamp of this row, timestamp stores data in UTC" />
- <column name="rowUpdatedUserId" type="${varchar50}" remarks="userId of the user who last updated this row"/>
- <column name="rowUpdated" type="timestamp" remarks="last update timestamp of this row, timestamp stores data in UTC" />
- </createTable>
-
- <!-- mandatory not null constraints on default columns -->
- <addNotNullConstraint columnName="id" columnDataType="int" schemaName="${table.schema}" tableName="${table.name}" />
- <addNotNullConstraint columnName="uuid" columnDataType="uuid" schemaName="${table.schema}" tableName="${table.name}" />
- <!-- TODO: disabled until user management is available <addNotNullConstraint columnName="rowCreatedUserId" columnDataType="${varchar50}" schemaName="${table.schema}" tableName="${table.name}" /> -->
- <addNotNullConstraint columnName="rowCreated" columnDataType="timestamp" schemaName="${table.schema}" tableName="${table.name}" />
- <!-- TODO: disabled until user management is available<addNotNullConstraint columnName="rowUpdatedUserId" columnDataType="${varchar50}" schemaName="${table.schema}" tableName="${table.name}" /> -->
- <addNotNullConstraint columnName="rowUpdated" columnDataType="timestamp" schemaName="${table.schema}" tableName="${table.name}" />
-
- <!-- create primary key -->
- <addPrimaryKey columnNames="id" constraintName="pk_${table.name}" schemaName="${table.schema}" tableName="${table.name}" />
- <addAutoIncrement columnName="id" columnDataType="int" tableName="${table.name}" />
-
- <!-- create unique index on uuid -->
- <createIndex indexName="Idx${table.name}Uuid" unique="true" schemaName="${table.schema}" tableName="${table.name}" >
- <column name="uuid" type="varchar(255)" />
- </createIndex>
- </changeSet>
- </databaseChangeLog>
and
the other files including it:
Translation.xml
- <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
- xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd
- http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
-
- <!-- include the default properties -->
- &propertiesAll;
-
- <property name="table.schema" value="${schema}" />
- <property name="table.name" value="Translations" />
- <property name="table.author" value="hkais" />
- <property name="changeset.number" value="001" />
- <property name="changeset.operation" value="Create" />
- <property name="changeset.name" value="${changeset.number}_${changeset.operation}${table.name}" />
-
- <!-- create default table ${table.name} -->
- <include file="000_DefaultTableTemplate.xml" relativeToChangelogFile="true" />
-
- <changeSet author="${table.author}" id="${changeset.name}">
- <addColumn schemaName="${schema}" tableName="${table.name}">
- <column name="locale" type="${varchar5}" beforeColumn="rowCreatedUserId" remarks="translation locale" />
- </addColumn>
- <addNotNullConstraint columnName="locale" columnDataType="${varchar5}" schemaName="${table.schema}" tableName="${table.name}" />
- </changeSet>
The varchar properties
are imported as xml entities at one place, so we have some
defaults for the developers and to keep them same for the
DBAs to administer their storages/tablespaces.
With the above changesets we
have nearly our solution, but only nearly.
The issue now is, since we
are using the property
${changeset.name}_DefaultTable
and we assumed this property gets renewed on every new changeset
file like the Translation.xml we get a collision due to
duplicateded ids of the changeset. So this lets me assume the
properties are immutable, or I am doing something wrong?
We
could debug in more depth in the IDE, but we would need some
advice there to take a look.
best wishes