<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xmlns:pro="http://www.liquibase.org/xml/ns/pro"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
    http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
    http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
    <changeSet author="Sheldan" id="tracked_emote-table">
        <createTable tableName="tracked_emote">
            <column name="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="name" type="VARCHAR(32)">
                <constraints nullable="false"/>
            </column>
            <column name="animated" type="BOOLEAN"/>
            <column name="tracking_enabled" type="BOOLEAN">
                <constraints nullable="false"/>
            </column>
            <column name="deleted" type="BOOLEAN">
                <constraints nullable="false"/>
            </column>
            <column name="external" type="BOOLEAN">
                <constraints nullable="false"/>
            </column>
            <column name="external_url" type="VARCHAR(255)"/>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <createIndex indexName="idx_tracked_emote_server_id" tableName="tracked_emote">
            <column name="server_id"/>
        </createIndex>
        <addPrimaryKey columnNames="server_id, id" tableName="tracked_emote" constraintName="pk_tracked_emote" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="tracked_emote" constraintName="fk_tracked_emote_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS tracked_emote_update_trigger ON tracked_emote;
            CREATE TRIGGER tracked_emote_update_trigger BEFORE UPDATE ON tracked_emote FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS tracked_emote_insert_trigger ON tracked_emote;
            CREATE TRIGGER tracked_emote_insert_trigger BEFORE INSERT ON tracked_emote FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>
</databaseChangeLog>