All Downloads are FREE. Search and download functionalities are using the official Maven repository.

installers.DynamicFormsModule.schema.xml Maven / Gradle / Ivy

The newest version!
<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ Copyright 2018 the original author or authors
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<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.1.xsd">

	<!-- Default table names -->
	<property name="table.definition_data_set" value="dfm_definition_data_set"/>
	<property name="table.definition_version" value="dfm_definition_version"/>
	<property name="table.allowed_definition_types" value="dfm_allowed_definition_types"/>
	<property name="table.definition" value="dfm_definition"/>
	<property name="table.document" value="dfm_document"/>
	<property name="table.document_version" value="dfm_document_version"/>

	<include file="com/foreach/across/core/installers/AcrossSequencesInstaller.xml"/>

	<changeSet id="201803181747" author="stg" runAlways="true" dbms="oracle">
		<sql>
			ALTER session SET nls_length_semantics=CHAR;
		</sql>
	</changeSet>

	<!-- Data Set -->
	<changeSet id="201803181350" author="marc">
		<preConditions onFail="MARK_RAN">
			<not>
				<tableExists tableName="${table.definition_data_set}"/>
			</not>
		</preConditions>

		<comment>Creates data set table</comment>
		<createTable tableName="${table.definition_data_set}">
			<column name="id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" primaryKey="true" primaryKeyName="pk_dfm_definition_data_set"/>
			</column>
			<column name="name" type="java.sql.Types.NVARCHAR(255)">
				<constraints nullable="false"/>
			</column>
			<column name="data_set_key" type="java.sql.Types.NVARCHAR(255)">
				<constraints nullable="false"/>
			</column>
		</createTable>
	</changeSet>

	<changeSet id="201803181351-remarks-fix-existing" author="marc">
		<preConditions onFail="MARK_RAN">
			<tableExists tableName="${table.definition_version}"/>
		</preConditions>

		<comment>Modifies definition version remarks column from nvarchar(4000) to NCLOB</comment>

		<addColumn tableName="${table.definition_version}">
			<column name="remarks_temp" type="java.sql.Types.NCLOB"/>
		</addColumn>
		<sql>UPDATE dfm_definition_version SET remarks_temp=remarks</sql>
		<dropColumn tableName="${table.definition_version}" columnName="remarks"/>
		<renameColumn tableName="${table.definition_version}" oldColumnName="remarks_temp" newColumnName="remarks" columnDataType="java.sql.Types.NCLOB"/>
	</changeSet>

	<changeSet id="201803181351-remarks-fix" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<tableExists tableName="${table.definition_version}"/>
			</not>
		</preConditions>

		<comment>Creates the definition version record</comment>

		<createTable tableName="${table.definition_version}">
			<column name="id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" primaryKey="true" primaryKeyName="pk_dfm_def_version"/>
			</column>
			<column name="definition_id" type="java.sql.Types.BIGINT">
				<constraints nullable="false"/>
			</column>
			<column name="definition_content" type="java.sql.Types.NCLOB">
				<constraints nullable="false"/>
			</column>
			<column name="version" type="java.sql.Types.NVARCHAR(30)">
				<constraints nullable="false"/>
			</column>
			<column name="remarks" type="java.sql.Types.NCLOB"/>
			<column name="published" type="java.sql.Types.BOOLEAN">
				<constraints nullable="false"/>
			</column>
		</createTable>
	</changeSet>

	<!-- Referential integrity table for definition types -->
	<changeSet id="201803181352" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<tableExists tableName="${table.allowed_definition_types}"/>
			</not>
		</preConditions>

		<comment>Creates referential integrity table for definition types</comment>

		<createTable tableName="${table.allowed_definition_types}">
			<column name="id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" primaryKey="true" primaryKeyName="pk_dfm_allowed_def_types"/>
			</column>

			<column name="name" type="java.sql.Types.VARCHAR(50)">
				<constraints nullable="false"/>
			</column>
		</createTable>
	</changeSet>

	<!-- DynamicDefinition -->
	<changeSet id="201803181353" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<tableExists tableName="${table.definition}"/>
			</not>

		</preConditions>

		<comment>Creates definition record table</comment>

		<createTable tableName="${table.definition}">
			<column name="id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" primaryKey="true" primaryKeyName="pk_dfm_definition"/>
			</column>
			<column name="name" type="java.sql.Types.NVARCHAR(255)">
				<constraints nullable="false"/>
			</column>
			<column name="definition_data_set_id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" referencedTableName="${table.definition_data_set}" referencedColumnNames="id"
				             foreignKeyName="fk_dfm_def_record_dataset"/>
			</column>
			<column name="definition_type" type="java.sql.Types.BIGINT">
				<constraints nullable="false" referencedTableName="${table.allowed_definition_types}" referencedColumnNames="id"
				             foreignKeyName="fk_dfm_def_rec_allowed_types"/>
			</column>
			<column name="latest_version_id" type="java.sql.Types.BIGINT">
				<constraints referencedTableName="${table.definition_version}" referencedColumnNames="id"
				             foreignKeyName="fk_dfm_def_record_def_version"/>
			</column>
		</createTable>
	</changeSet>

	<changeSet id="201806200930" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<foreignKeyConstraintExists foreignKeyName="fk_dfm_def_version_def"/>
			</not>
		</preConditions>

		<comment>Creates foreign key from version record to definition record</comment>

		<addForeignKeyConstraint baseTableName="${table.definition_version}" baseColumnNames="definition_id"
		                         constraintName="fk_dfm_def_version_def" referencedTableName="${table.definition}"
		                         referencedColumnNames="id"/>
	</changeSet>

	<!-- DynamicDocument -->
	<changeSet id="201803181755" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<tableExists tableName="${table.document}"/>
			</not>
		</preConditions>

		<comment>Creates document table</comment>

		<createTable tableName="${table.document}">
			<column name="id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" primaryKey="true" primaryKeyName="pk_dfm_document"/>
			</column>
			<column name="name" type="java.sql.Types.NVARCHAR(255)">
				<constraints nullable="false"/>
			</column>
			<column name="definition_id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" referencedTableName="${table.definition}" referencedColumnNames="id"
				             foreignKeyName="fk_dfm_document_definition"/>
			</column>
			<column name="versionable" type="java.sql.Types.BOOLEAN">
				<constraints nullable="false"/>
			</column>
			<column name="latest_version_id" type="java.sql.Types.BIGINT"/>
		</createTable>
	</changeSet>

	<changeSet id="201803181800" author="marc">
		<comment>Create a unique key constraint on definition record and version</comment>
		<addUniqueConstraint tableName="${table.definition_version}" columnNames="definition_id, version"
		                     constraintName="uq_dfm_def_version_rec"/>
	</changeSet>

	<changeSet id="201804060839" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<tableExists tableName="${table.document_version}"/>
			</not>
		</preConditions>

		<comment>Creates the document version table</comment>

		<createTable tableName="${table.document_version}">
			<column name="id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" primaryKey="true" primaryKeyName="pk_dfm_document_version"/>
			</column>
			<column name="document_id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" foreignKeyName="fk_dfm_doc_version_document" referencedColumnNames="id" referencedTableName="${table.document}"/>
			</column>
			<column name="definition_version_id" type="java.sql.Types.BIGINT">
				<constraints nullable="false" foreignKeyName="fk_dfm_doc_version_definition" referencedColumnNames="id"
				             referencedTableName="${table.definition_version}"/>
			</column>
			<column name="version" type="java.sql.Types.NVARCHAR(30)">
				<constraints nullable="false"/>
			</column>
			<column name="document_content" type="java.sql.Types.NCLOB">
				<constraints nullable="true"/>
			</column>
		</createTable>
	</changeSet>

	<changeSet id="201804060848" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<foreignKeyConstraintExists foreignKeyName="fk_dfm_doc_doc_version"
				                            foreignKeyTableName="${table.document}"/>
			</not>
		</preConditions>

		<comment>Creates the foreign key from document to document version</comment>

		<addForeignKeyConstraint baseTableName="${table.document}"
		                         baseColumnNames="latest_version_id"
		                         constraintName="fk_dfm_doc_doc_version"
		                         referencedTableName="${table.document_version}"
		                         referencedColumnNames="id"/>
	</changeSet>

	<changeSet id="201805021103" author="marc">
		<comment>Create a unique key constraint on data set, key</comment>
		<addUniqueConstraint tableName="${table.definition_data_set}" columnNames="data_set_key"
		                     constraintName="uq_dfm_def_ds_key"/>
	</changeSet>

	<changeSet id="201806201604" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<columnExists tableName="${table.definition}" columnName="definition_key"/>
			</not>
		</preConditions>

		<comment>Modify definition table to add key column</comment>

		<addColumn tableName="${table.definition}">
			<column name="definition_key" type="java.sql.Types.NVARCHAR(150)"/>
		</addColumn>
	</changeSet>

	<changeSet id="201806201606" author="stg">
		<preConditions onFail="MARK_RAN">
			<and>
				<not>
					<dbms type="mssql"/>
				</not>
				<columnExists tableName="${table.definition}" columnName="definition_key"/>
				<not>
					<indexExists tableName="${table.definition}" indexName="ix_dfm_def_key_ds"/>
				</not>
			</and>
		</preConditions>
		<comment>Create keys for existing definitions based on id</comment>
		<update tableName="${table.definition}">
			<column name="definition_key" valueComputed="('generated-'||id)" type="java.sql.Types.NVARCHAR(150)"/>
		</update>
		<addNotNullConstraint tableName="${table.definition}" columnName="definition_key" columnDataType="java.sql.Types.NVARCHAR(150)"/>

		<createIndex tableName="${table.definition}" indexName="ix_dfm_def_key_ds" unique="true">
			<column name="definition_type"/>
			<column name="definition_data_set_id"/>
			<column name="definition_key"/>
		</createIndex>
	</changeSet>

	<changeSet id="201806201608" author="stg">
		<preConditions onFail="MARK_RAN">
			<and>
				<dbms type="mssql"/>
				<columnExists tableName="${table.definition}" columnName="definition_key"/>
				<not>
					<indexExists tableName="${table.definition}" indexName="ix_dfm_def_key_ds"/>
				</not>
			</and>
		</preConditions>
		<comment>Create keys for existing definitions based on id - sql server</comment>
		<update tableName="${table.definition}">
			<column name="definition_key" valueComputed="('generated-' + cast(id AS VARCHAR))" type="java.sql.Types.NVARCHAR(150)"/>
		</update>

		<addNotNullConstraint tableName="${table.definition}" columnName="definition_key" columnDataType="java.sql.Types.NVARCHAR(150)"/>

		<createIndex tableName="${table.definition}" indexName="ix_dfm_def_key_ds" unique="true">
			<column name="definition_type"/>
			<column name="definition_data_set_id"/>
			<column name="definition_key"/>
		</createIndex>
	</changeSet>

	<changeSet id="201805311429" author="stg">
		<preConditions onFail="MARK_RAN">
			<not>
				<columnExists tableName="${table.definition}" columnName="parent_definition_id"/>
			</not>
		</preConditions>

		<comment>Modify definition table to add a link to the parent definition</comment>

		<addColumn tableName="${table.definition}">
			<column name="parent_definition_id" type="java.sql.Types.BIGINT">
				<constraints foreignKeyName="fk_dfm_def_parent_def" referencedColumnNames="id" referencedTableName="${table.definition}"/>
			</column>
		</addColumn>
	</changeSet>

	<changeSet id="201809131617" author="marc">
		<preConditions onFail="MARK_RAN">
			<dbms type="mysql"/>
			<indexExists tableName="${table.definition}" indexName="ix_dfm_def_key_ds"/>
		</preConditions>

		<comment>Modify unique index for definition keys for MySQL requires dropping the Foreign Key constraint</comment>

		<dropForeignKeyConstraint baseTableName="${table.definition}" constraintName="fk_dfm_def_rec_allowed_types"/>
		<dropIndex tableName="${table.definition}" indexName="ix_dfm_def_key_ds"/>
		<createIndex tableName="${table.definition}" indexName="ix_dfm_def_key_ds" unique="true">
			<column name="definition_type"/>
			<column name="definition_data_set_id"/>
			<column name="definition_key"/>
			<column name="parent_definition_id"/>
		</createIndex>
		<addForeignKeyConstraint baseTableName="${table.definition}" baseColumnNames="definition_type"
		                         constraintName="fk_dfm_def_rec_allowed_types"
		                         referencedTableName="${table.allowed_definition_types}" referencedColumnNames="id"/>
	</changeSet>

	<changeSet id="201809131618" author="marc">
		<preConditions onFail="MARK_RAN">
			<not>
				<dbms type="mysql"/>
			</not>
			<indexExists tableName="${table.definition}" indexName="ix_dfm_def_key_ds"/>
		</preConditions>

		<comment>Modify unique index for definition keys</comment>

		<dropIndex tableName="${table.definition}" indexName="ix_dfm_def_key_ds"/>
		<createIndex tableName="${table.definition}" indexName="ix_dfm_def_key_ds" unique="true">
			<column name="definition_type"/>
			<column name="definition_data_set_id"/>
			<column name="definition_key"/>
			<column name="parent_definition_id"/>
		</createIndex>
	</changeSet>
</databaseChangeLog>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy