<?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="user_experience-table">
        <createTable tableName="user_experience">
            <column name="id" type="BIGINT">
                <constraints nullable="false" primaryKey="true" primaryKeyName="user_experience_pkey"/>
            </column>
            <column name="experience" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="experience_gain_disabled" type="BOOLEAN">
                <constraints nullable="false"/>
            </column>
            <column name="message_count" 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"/>
            <column name="role_id" type="BIGINT"/>
            <column name="level_id" type="INTEGER">
                <constraints nullable="false"/>
            </column>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <addForeignKeyConstraint baseColumnNames="level_id" baseTableName="user_experience" constraintName="fk_user_experience_level" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="level" referencedTableName="experience_level" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="role_id" baseTableName="user_experience" constraintName="fk_user_experience_role" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="experience_role" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="user_experience" constraintName="fk_user_experience_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS user_experience_update_trigger ON user_experience;
            CREATE TRIGGER user_experience_update_trigger BEFORE UPDATE ON user_experience FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS user_experience_insert_trigger ON user_experience;
            CREATE TRIGGER user_experience_insert_trigger BEFORE INSERT ON user_experience FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>

</databaseChangeLog>