





<?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"
                   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.0.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <changeSet id="1" author="activiti">

        <createTable tableName="ACT_DMN_DEPLOYMENT">
            <column name="ID_" type="varchar(255)">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="NAME_" type="varchar(255)" />
            <column name="CATEGORY_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="DEPLOY_TIME_" type="datetime">
                <constraints nullable="true" />
            </column>
            <column name="TENANT_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="PARENT_DEPLOYMENT_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
        </createTable>

        <createTable tableName="ACT_DMN_DEPLOYMENT_RESOURCE">
            <column name="ID_" type="varchar(255)">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="NAME_" type="varchar(255)" />
            <column name="DEPLOYMENT_ID_" type="varchar(255)" />
            <column name="RESOURCE_BYTES_" type="longblob">
                <constraints nullable="true" />
            </column>
        </createTable>

        <createTable tableName="ACT_DMN_DECISION_TABLE">
            <column name="ID_" type="varchar(255)">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="NAME_" type="varchar(255)" />
            <column name="VERSION_" type="int" />
            <column name="KEY_" type="varchar(255)" />
            <column name="CATEGORY_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="DEPLOYMENT_ID_" type="varchar(255)" />
            <column name="PARENT_DEPLOYMENT_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="TENANT_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="RESOURCE_NAME_" type="varchar(255)" />
            <column name="DESCRIPTION_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
        </createTable>

    </changeSet>

    <changeSet id="2" author="flowable">

        <createTable tableName="ACT_DMN_HI_DECISION_EXECUTION">
            <column name="ID_" type="varchar(255)">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="DECISION_DEFINITION_ID_" type="varchar(255)" />
            <column name="DEPLOYMENT_ID_" type="varchar(255)" />
            <column name="START_TIME_" type="datetime" />
            <column name="END_TIME_" type="datetime">
                <constraints nullable="true" />
            </column>
            <column name="INSTANCE_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="EXECUTION_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="ACTIVITY_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="FAILED_" type="boolean" defaultValueBoolean="false" />
            <column name="TENANT_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="EXECUTION_JSON_" type="longtext">
                <constraints nullable="true" />
            </column>
        </createTable>

    </changeSet>

    <changeSet id="2" author="flowable">

        <createTable tableName="ACT_DMN_HI_DECISION_EXECUTION">
            <column name="ID_" type="varchar(255)">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="DECISION_DEFINITION_ID_" type="varchar(255)" />
            <column name="DEPLOYMENT_ID_" type="varchar(255)" />
            <column name="START_TIME_" type="datetime" />
            <column name="END_TIME_" type="datetime">
                <constraints nullable="true" />
            </column>
            <column name="INSTANCE_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="EXECUTION_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="ACTIVITY_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="FAILED_" type="boolean" defaultValueBoolean="false" />
            <column name="TENANT_ID_" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="EXECUTION_JSON_" type="longtext">
                <constraints nullable="true" />
            </column>
        </createTable>

    </changeSet>

    <changeSet id="3" author="flowable">

        <addColumn tableName="ACT_DMN_HI_DECISION_EXECUTION">
            <column name="SCOPE_TYPE_" type="varchar(255)" />
        </addColumn>

    </changeSet>

    <changeSet id="4" author="flowable">

        <dropColumn columnName="PARENT_DEPLOYMENT_ID_" tableName="ACT_DMN_DECISION_TABLE" />

    </changeSet>

    <changeSet id="5" author="flowable" dbms="mysql,mariadb">

        <modifyDataType tableName="ACT_DMN_DEPLOYMENT" columnName="DEPLOY_TIME_" newDataType="datetime(3)" />
        <modifyDataType tableName="ACT_DMN_HI_DECISION_EXECUTION" columnName="START_TIME_" newDataType="datetime(3)" />
        <modifyDataType tableName="ACT_DMN_HI_DECISION_EXECUTION" columnName="END_TIME_" newDataType="datetime(3)" />

    </changeSet>

    <changeSet id="6" author="flowable">

        <createIndex tableName="ACT_DMN_DECISION_TABLE" indexName="ACT_IDX_DEC_TBL_UNIQ" unique="true">
            <column name="KEY_" />
            <column name="VERSION_" />
            <column name="TENANT_ID_" />
        </createIndex>

    </changeSet>

    <changeSet id="7" author="flowable" dbms="!dm">

        <dropIndex tableName="ACT_DMN_DECISION_TABLE" indexName="ACT_IDX_DEC_TBL_UNIQ"/>

        <renameTable
                newTableName="ACT_DMN_DECISION"
                oldTableName="ACT_DMN_DECISION_TABLE"/>

        <createIndex tableName="ACT_DMN_DECISION" indexName="ACT_IDX_DMN_DEC_UNIQ" unique="true">
            <column name="KEY_" />
            <column name="VERSION_" />
            <column name="TENANT_ID_" />
        </createIndex>

    </changeSet>

    <changeSet id="7" author="flowable" dbms="dm">
        <dropIndex tableName="ACT_DMN_DECISION_TABLE" indexName="ACT_IDX_DEC_TBL_UNIQ"/>
        <sql>
            CREATE TABLE ACT_DMN_DECISION AS SELECT * FROM ACT_DMN_DECISION_TABLE;
        </sql>
        <sql>
            DROP TABLE ACT_DMN_DECISION_TABLE;
        </sql>
        <createIndex tableName="ACT_DMN_DECISION" indexName="ACT_IDX_DMN_DEC_UNIQ" unique="true">
            <column name="KEY_" />
            <column name="VERSION_" />
            <column name="TENANT_ID_" />
        </createIndex>
    </changeSet>


    <changeSet id="8" author="flowable">

        <addColumn tableName="ACT_DMN_DECISION">
            <column name="DECISION_TYPE_" type="varchar(255)" />
        </addColumn>

    </changeSet>

</databaseChangeLog>





