<?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="filtered_invite_link-table">
        <createTable tableName="filtered_invite_link">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints nullable="false" primaryKey="true" primaryKeyName="filtered_invite_link_pkey"/>
            </column>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="true"/>
            </column>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
            <column name="uses" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="target_server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="server_name" type="VARCHAR(100)">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <createIndex indexName="idx_filtered_invite_link_server" tableName="filtered_invite_link">
            <column name="server_id"/>
        </createIndex>
        <createIndex indexName="idx_filtered_invite_link_target_server_server" tableName="filtered_invite_link">
            <column name="target_server_id"/>
            <column name="server_id"/>
        </createIndex>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="filtered_invite_link" constraintName="fk_filtered_invite_link_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS filtered_invite_link_update_trigger ON filtered_invite_link;
            CREATE TRIGGER filtered_invite_link_update_trigger BEFORE UPDATE ON filtered_invite_link FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS filtered_invite_link_insert_trigger ON filtered_invite_link;
            CREATE TRIGGER filtered_invite_link_insert_trigger BEFORE INSERT ON filtered_invite_link FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>

</databaseChangeLog>