<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-sequence-table" author="sasko.tanaskoski">
        <createTable tableName="acm_sequence">
            <column name="cm_sequence_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_value" type="${idType}">
                <constraints nullable="false"/>
            </column>
            <column name="version" type="INTEGER" defaultValue="1">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <addPrimaryKey tableName="acm_sequence" columnNames="cm_sequence_name, cm_sequence_part_name"/>
    </changeSet>
    <changeSet id="02-create-sequence-registry-table" author="sasko.tanaskoski">
        <createTable tableName="acm_sequence_registry">
            <column name="cm_sequence_value" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_value" type="${idType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_value_used_flag" type="VARCHAR(10)" defaultValue="true"/>
        </createTable>
        <addPrimaryKey tableName="acm_sequence_registry" columnNames="cm_sequence_value, cm_sequence_name, cm_sequence_part_name"/>
    </changeSet>
    <changeSet id="03-create-sequence-reset-table" author="sasko.tanaskoski">
        <createTable tableName="acm_sequence_reset">
            <column name="cm_sequence_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_reset_date" type="${timestampType}"/>
            <column name="cm_reset_executed_date" type="${timestampType}"/>
            <column name="cm_reset_executed_flag" type="VARCHAR(10)" defaultValue="false"/>
            <column name="cm_reset_repeatable_flag" type="VARCHAR(10)" defaultValue="false"/>
            <column name="cm_reset_repeatable_period" type="INTEGER" defaultValue="0"/>
        </createTable>
        <addPrimaryKey tableName="acm_sequence_reset" columnNames="cm_sequence_name, cm_sequence_part_name, cm_reset_date"/>
    </changeSet>

    <changeSet id="04-change_cm_sequence_reset_datetime" author="mario.gjurcheski" dbms="mysql">
        <modifyDataType tableName="acm_sequence_reset" columnName="cm_reset_date" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_sequence_reset" columnName="cm_reset_executed_date" newDataType="DATETIME"/>
    </changeSet>
    <changeSet id="05-drop-sequence-part-value-used-flag-column" author="adrijana.maneva">
        <dropColumn tableName="acm_sequence_registry" columnName="cm_sequence_part_value_used_flag"/>
    </changeSet>
    <changeSet id="06-create-used-sequence-registry-table" author="adrijana.maneva">
        <createTable tableName="acm_sequence_registry_used">
            <column name="cm_sequence_value" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_sequence_part_value" type="${idType}">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <addPrimaryKey tableName="acm_sequence_registry_used" columnNames="cm_sequence_value, cm_sequence_name, cm_sequence_part_name"/>
    </changeSet>
</databaseChangeLog>
