<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-acm_authentication_token-id" author="mnj11">
        <createTable tableName="acm_authentication_token_id">
            <column name="cm_seq_num" type="${idType}"/>
            <column name="cm_seq_name" type="VARCHAR(255)"/>
        </createTable>
        <insert tableName="acm_authentication_token_id">
            <column name="cm_seq_num" value="100"></column>
            <column name="cm_seq_name" value="acm_authentication_token"></column>
        </insert>
    </changeSet>
    <changeSet id="02-acm_authentication_token-constraint-file-id" author="mnj11">
        <preConditions>
            <and>
                <tableExists tableName="acm_file"/>
                <columnExists tableName="acm_authentication_token" columnName="cm_authentication_token_file_id"/>
            </and>
        </preConditions>
        <addForeignKeyConstraint baseTableName="acm_authentication_token" baseColumnNames="cm_authentication_token_file_id"
                                 constraintName="fk_authentication_token_file_id" referencedTableName="acm_file"
                                 referencedColumnNames="cm_file_id"
                                 deferrable="${deferrable}" initiallyDeferred="${initially.deferred}"/>
    </changeSet>

    <changeSet id="03-create-auth-token-index" author="ncuculova"
               logicalFilePath="/com/armedia/acm/ddl/tables/authenticationtoken-database-tables.xml">
        <createIndex tableName="acm_authentication_token" indexName="idx_auth_token_key">
            <column name="cm_authentication_token_key"/>
        </createIndex>
        <addUniqueConstraint tableName="acm_authentication_token" columnNames="cm_authentication_token_key"/>
    </changeSet>

    <changeSet id="04-drop-not-null-email-constraint" author="martin.bozinovski">
        <dropNotNullConstraint tableName="acm_authentication_token" columnName="cm_authentication_token_email" columnDataType="VARCHAR(512)" />
    </changeSet>

    <changeSet id="05-acm_authentication_token_constraint_relative-path" author="stefan.sanevski">
        <addUniqueConstraint tableName="acm_authentication_token" columnNames="cm_authentication_token_key, cm_authentication_token_relative_path"/>
    </changeSet>

</databaseChangeLog>