<?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="custom_command-table">
        <createTable tableName="custom_command">
            <column name="id" type="BIGINT">
                <constraints nullable="false" primaryKey="true" primaryKeyName="custom_command_pkey"/>
            </column>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="false"/>
            </column>
            <column name="creator_user_in_server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="additional_message" type="VARCHAR(2048)">
                <constraints nullable="false"/>
            </column>
            <column name="NAME" type="VARCHAR(64)">
                <constraints nullable="false"/>
            </column>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
        </createTable>
        <addUniqueConstraint columnNames="name"
                             constraintName="uc_custom_command_name"
                             disabled="false"
                             tableName="custom_command"/>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="custom_command"
                                 constraintName="fk_custom_command_server" deferrable="false" initiallyDeferred="false"
                                 onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="creator_user_in_server_id" baseTableName="custom_command"
                                 constraintName="fk_custom_command_creator" 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 custom_command_update_trigger ON custom_command;
            CREATE TRIGGER custom_command_update_trigger BEFORE UPDATE ON custom_command FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS custom_command_insert_trigger ON custom_command;
            CREATE TRIGGER custom_command_insert_trigger BEFORE INSERT ON custom_command FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>

</databaseChangeLog>