<?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.3.xsd" >

    <changeSet author="Sheldan" id="sticky_role_user-table">
        <createTable tableName="sticky_role_user">
            <column name="id" type="BIGINT">
                <constraints nullable="false" primaryKey="true" primaryKeyName="pk_sticky_role_user"/>
            </column>
            <column name="sticky" type="BOOLEAN" defaultValue="true">
                <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="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <addForeignKeyConstraint baseColumnNames="id" baseTableName="sticky_role_user" constraintName="fk_sticky_role_user_user"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="user_in_server_id" referencedTableName="user_in_server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="sticky_role_user"
                                 constraintName="fk_sticky_role_user_server" deferrable="false" initiallyDeferred="false"
                                 onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server"
                                 validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS sticky_role_user_update_trigger ON sticky_role_user;
            CREATE TRIGGER sticky_role_user_update_trigger BEFORE UPDATE ON sticky_role_user FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS sticky_role_user_insert_trigger ON sticky_role_user;
            CREATE TRIGGER sticky_role_user_insert_trigger BEFORE INSERT ON sticky_role_user FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>

    <changeSet author="Sheldan" id="sticky_role_user_mapping-table">
        <createTable tableName="sticky_role_user_mapping">
            <column name="role_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="user_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="role_id" baseTableName="sticky_role_user_mapping" constraintName="fk_sticky_role_user_mapping_role"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="sticky_role" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="user_id" baseTableName="sticky_role_user_mapping" constraintName="fk_sticky_role_user_mapping_user"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="sticky_role_user" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS sticky_role_user_mapping_update_trigger ON sticky_role_user_mapping;
            CREATE TRIGGER sticky_role_user_mapping_update_trigger BEFORE UPDATE ON sticky_role_user_mapping FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS sticky_role_user_mapping_insert_trigger ON sticky_role_user_mapping;
            CREATE TRIGGER sticky_role_user_mapping_insert_trigger BEFORE INSERT ON sticky_role_user_mapping FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>
</databaseChangeLog>