<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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 https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
    <changeSet author="Sheldan" id="used_emote-table">
        <createTable tableName="used_emote">
            <column name="emote_id" type="BIGINT" >
                <constraints nullable="false"/>
            </column>
            <column name="server_id" type="BIGINT" >
                <constraints nullable="false"/>
            </column>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="false"/>
            </column>
            <column name="use_date" type="DATE" >
                <constraints nullable="false"/>
            </column>
            <column name="amount" type="BIGINT">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <createIndex indexName="idx_used_emote" tableName="used_emote">
            <column name="emote_id"/>
            <column name="server_id"/>
            <column name="use_date"/>
        </createIndex>
        <addPrimaryKey columnNames="server_id, emote_id, use_date" tableName="used_emote" constraintName="pk_used_emote" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="used_emote" constraintName="fk_used_emote_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="emote_id, server_id" baseTableName="used_emote" constraintName="fk_used_emote_tracked_emote" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id, server_id" referencedTableName="tracked_emote" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS used_emote_update_trigger ON used_emote;
            CREATE TRIGGER used_emote_update_trigger BEFORE UPDATE ON used_emote FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS used_emote_insert_trigger ON used_emote;
            CREATE TRIGGER used_emote_insert_trigger BEFORE INSERT ON used_emote FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>

</databaseChangeLog>