<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet id="1" author="anevrekar">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_insert_mkt_priority_project;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_mkt_priority_project AFTER INSERT ON mkt_priority_project
                FOR EACH ROW 
                    BEGIN
                        INSERT INTO `art_relations_log`.`mkt_priority_project_log` SET
                        `log_timestamp` = NOW(),
                        `log_action` = 'insert',
                        `mkt_priority_project_id` = NEW.`mkt_priority_project_id`,
                        `project_id` = NEW.`project_id`,
                        `priority` = NEW.`priority`,
                        `country_id` = NEW.`country_id`,
                        `created_by` = NEW.`created_by`,
                        `updated_by` = NEW.`created_by`,
                        `created_on` = NEW.`created_on`,
                        `updated_on` = NEW.`updated_on`;
                    END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_insert_mkt_priority_project`;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="2" author="anevrekar">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_update_mkt_priority_project;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_update_mkt_priority_project AFTER UPDATE ON mkt_priority_project
                FOR EACH ROW 
                    BEGIN
                        INSERT INTO `art_relations_log`.`mkt_priority_project_log` SET
                        `log_timestamp` = NOW(),
                        `log_action` = 'update',
                        `mkt_priority_project_id` = NEW.`mkt_priority_project_id`,
                        `project_id` = NEW.`project_id`,
                        `priority` = NEW.`priority`,
                        `country_id` = NEW.`country_id`,
                        `created_by` = NEW.`created_by`,
                        `updated_by` = NEW.`created_by`,
                        `created_on` = NEW.`created_on`,
                        `updated_on` = NEW.`updated_on`;
                    END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_update_mkt_priority_project`;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="3" author="anevrekar">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE `art_relations`;;

                DROP TRIGGER IF EXISTS `after_delete_mkt_priority_project`;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_delete_mkt_priority_project AFTER DELETE ON mkt_priority_project
                FOR EACH ROW
                BEGIN
                    INSERT INTO `art_relations_log`.`mkt_priority_project_log` SET
                    `log_timestamp` = NOW(),
                    `log_action` = 'delete',
                    `mkt_priority_project_id` = OLD.`mkt_priority_project_id`,
                    `project_id` = OLD.`project_id`,
                    `priority` = OLD.`priority`,
                    `country_id` = OLD.`country_id`,
                    `created_by` = OLD.`created_by`,
                    `updated_by` = OLD.`created_by`,
                    `created_on` = OLD.`created_on`,
                    `updated_on` = OLD.`updated_on`;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_delete_mkt_priority_project`;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
