<?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="custom_template-table">
        <createTable tableName="custom_template">
            <column name="key" type="VARCHAR(255)">
                <constraints nullable="false" />
            </column>
            <column name="section" type="VARCHAR(255)"/>
            <column name="last_modified" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="false"/>
            </column>
            <column name="content" type="VARCHAR(4000)"/>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE"/>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <addPrimaryKey columnNames="server_id, key" tableName="custom_template" constraintName="pk_custom_template" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS custom_template_update_trigger ON custom_template;
            CREATE TRIGGER custom_template_update_trigger BEFORE UPDATE ON custom_template FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS custom_template_insert_trigger ON custom_template;
            CREATE TRIGGER custom_template_insert_trigger BEFORE INSERT ON custom_template FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS custom_template_last_modified_trigger ON custom_template;
            CREATE TRIGGER custom_template_last_modified_trigger BEFORE UPDATE ON custom_template FOR EACH ROW EXECUTE PROCEDURE last_modified_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS custom_template_last_modified_insert_trigger ON custom_template;
            CREATE TRIGGER custom_template_last_modified_insert_trigger BEFORE INSERT ON custom_template FOR EACH ROW EXECUTE PROCEDURE last_modified_trigger_procedure();
        </sql>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="custom_template" constraintName="fk_custom_template_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="key" baseTableName="custom_template" constraintName="fk_custom_template_template" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="key" referencedTableName="template" validate="true"/>
    </changeSet>
</databaseChangeLog>