<?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="reaction_report-table">
        <createTable tableName="reaction_report">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints nullable="false" primaryKey="true" primaryKeyName="pk_reaction_report"/>
            </column>
            <column name="reported_user_in_server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="report_channel_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="reported_message_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="reported_channel_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="report_count" type="INT">
                <constraints nullable="false"/>
            </column>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="false"/>
            </column>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
        </createTable>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="reaction_report" constraintName="fk_reaction_report_server"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="reported_channel_id" baseTableName="reaction_report" constraintName="fk_reaction_report_reported_channel"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="channel" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="report_channel_id" baseTableName="reaction_report" constraintName="fk_reaction_report_report_channel"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="channel" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="reported_user_in_server_id" baseTableName="reaction_report" constraintName="fk_reaction_report_reported_user"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="user_in_server_id" referencedTableName="user_in_server" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS reaction_report_update_trigger ON reaction_report;
            CREATE TRIGGER reaction_report_update_trigger BEFORE UPDATE ON reaction_report FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS reaction_report_insert_trigger ON reaction_report;
            CREATE TRIGGER reaction_report_insert_trigger BEFORE INSERT ON reaction_report FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>

</databaseChangeLog>