<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">

    <property name="cmUserIdLength" value="1024" dbms="postgresql,oracle"/>
    <property name="cmUserIdLength" value="255" dbms="mysql,mssql"/>

    <property name="cmObjectTypeLength" value="1024" dbms="postgresql,oracle"/>
    <property name="cmObjectTypeLength" value="255" dbms="mysql,mssql"/>

    <changeSet id="01-create-object-history-table-fix" author="nebojsha.davidovikj" dbms="oracle,postgresql,mssql">
        <createTable tableName="acm_object_history">
            <column name="cm_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_cm_object_history_id"/>
            </column>
            <column name="cm_object_id" type="${fkIdType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_object_type" type="VARCHAR(${cmObjectTypeLength})">
                <constraints nullable="false"/>
            </column>
            <column name="cm_object_string" type="CLOB">
                <constraints nullable="false"/>
            </column>
            <column name="cm_user_id" type="VARCHAR(${cmUserIdLength})">
                <constraints nullable="false"/>
            </column>
            <column name="cm_date" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_type" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_created" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_modified" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>

    <changeSet id="01-create-object-history-table-fix" author="nebojsha.davidovikj" dbms="mysql">
        <createTable tableName="acm_object_history">
            <column name="cm_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_cm_object_history_id"/>
            </column>
            <column name="cm_object_id" type="${fkIdType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_object_type" type="VARCHAR(${cmObjectTypeLength})">
                <constraints nullable="false"/>
            </column>
            <column name="cm_object_string" type="CLOB">
                <constraints nullable="false"/>
            </column>
            <column name="cm_user_id" type="VARCHAR(${cmUserIdLength})">
                <constraints nullable="false"/>
            </column>
            <column name="cm_date" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_type" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_created" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_modified" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>

    <changeSet id="06-create-assignment-table" author="riste.tutureski" dbms="oracle,postgresql,mssql">
        <createTable tableName="acm_assignment">
            <column name="cm_assignment_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_cm_assignment_id"/>
            </column>
            <column name="cm_assignment_object_id" type="${fkIdType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_object_type" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_object_title" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_object_name" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_new_assignee" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_old_assignee" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_assignment_created" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_modified" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>

    <changeSet id="06-create-assignment-table" author="riste.tutureski" dbms="mysql">
        <createTable tableName="acm_assignment">
            <column name="cm_assignment_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_cm_assignment_id"/>
            </column>
            <column name="cm_assignment_object_id" type="${fkIdType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_object_type" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_object_title" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_object_name" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_new_assignee" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_old_assignee" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_assignment_created" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_modified" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_assignment_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>

    <changeSet id="07-acm_object_history-id" author="nebojsha.davidovikj">
        <createTable tableName="acm_object_history_id">
            <column name="cm_seq_num" type="${idType}"/>
            <column name="cm_seq_name" type="VARCHAR(255)"/>
        </createTable>
        <insert tableName="acm_object_history_id">
            <column name="cm_seq_num" value="100"></column>
            <column name="cm_seq_name" value="acm_object_history"></column>
        </insert>
    </changeSet>

    <changeSet id="08-acm_assignment-id" author="nebojsha.davidovikj">
        <createTable tableName="acm_assignment_id">
            <column name="cm_seq_num" type="${idType}"/>
            <column name="cm_seq_name" type="VARCHAR(255)"/>
        </createTable>
        <insert tableName="acm_assignment_id">
            <column name="cm_seq_num" value="100"></column>
            <column name="cm_seq_name" value="acm_assignment"></column>
        </insert>
    </changeSet>

    <changeSet id="09-change_cm_assignment_created" author="mario.gjurcheski" dbms="mysql">
        <modifyDataType tableName="acm_assignment" columnName="cm_assignment_created" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_assignment" columnName="cm_assignment_modified" newDataType="DATETIME"/>
    </changeSet>

    <changeSet id="10-change-character-set-to-object-history-string" author="konstantin.cepas" dbms="mysql">
        <sql>
            ALTER IGNORE TABLE acm_object_history MODIFY COLUMN cm_object_string LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
        </sql>
    </changeSet>

    <changeSet id="11-change-character-set-to--history-string" author="konstantin.cepas" dbms="mysql">
        <sql>
            ALTER IGNORE TABLE acm_assignment MODIFY COLUMN cm_assignment_object_title VARCHAR(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
        </sql>
    </changeSet>

</databaseChangeLog>