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

    <changeSet id="01-create-object-history-constraints" author="riste.tutureski">
        <addForeignKeyConstraint baseTableName="acm_object_history" baseColumnNames="cm_user_id" constraintName="fk_object_history_user_id"
            referencedTableName="acm_user" referencedColumnNames="cm_user_id" deferrable="${deferrable}"
            initiallyDeferred="${initially.deferred}"/>
    </changeSet>

    <changeSet id="02-create-object-history-index" author="riste.tutureski">
        <createIndex tableName="acm_object_history" indexName="idx_object_history_object_id">
            <column name="cm_object_id"/>
        </createIndex>
        <createIndex tableName="acm_object_history" indexName="idx_object_history_object_type">
            <column name="cm_object_type"/>
        </createIndex>
    </changeSet>

    <changeSet id="03-remove-object-history-foreign-key" author="riste.tutureski">
        <dropForeignKeyConstraint baseTableName="acm_object_history" constraintName="fk_object_history_user_id"/>
    </changeSet>

    <changeSet id="04-remove-object-history-indexes" author="riste.tutureski">
        <dropIndex tableName="acm_object_history" indexName="idx_object_history_object_id"/>
        <dropIndex tableName="acm_object_history" indexName="idx_object_history_object_type"/>
    </changeSet>

    <changeSet id="05-create-object-history-index" author="riste.tutureski"
        logicalFilePath="/com/armedia/acm/ddl/tables/object-history-service-database-tables.xml">
        <createIndex tableName="acm_object_history" indexName="idx_object_history_id_type">
            <column name="cm_object_id"/>
            <column name="cm_object_type"/>
        </createIndex>
    </changeSet>

    <changeSet id="07-remove-nullable-for-newasignee-in-assignment-table" author="riste.tutureski"
        logicalFilePath="/com/armedia/acm/ddl/tables/object-history-service-database-tables.xml">
        <dropNotNullConstraint tableName="acm_assignment" columnName="cm_assignment_new_assignee" columnDataType="VARCHAR(1024)"/>
    </changeSet>

    <changeSet id="08-change-cm-object-history-datetime" author="marija.blazhevska">
        <modifyDataType tableName="acm_object_history" columnName="cm_modified" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_object_history" columnName="cm_date" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_object_history" columnName="cm_created" newDataType="DATETIME"/>
    </changeSet>

</databaseChangeLog>