<?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_concierge_product;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_concierge_product AFTER INSERT ON concierge_product
                FOR EACH ROW 
                    BEGIN
                        INSERT INTO `art_relations_log`.`concierge_product_log` SET
                        `log_timestamp` = NOW(),
                        `log_action` = 'insert',
                        `concierge_product_id` = NEW.`concierge_product_id`,
                        `product_id` = NEW.`product_id`,
                        `concierge_value` = NEW.`concierge_value`,
                        `last_updated` = NEW.`last_updated`,
                        `updated_by` = NEW.`updated_by`;
                    END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_insert_concierge_product`;;
            ]]>
            </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_concierge_product;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_update_concierge_product AFTER UPDATE ON concierge_product
                FOR EACH ROW 
                    BEGIN
                        INSERT INTO `art_relations_log`.`concierge_product_log` SET
                        `log_timestamp` = NOW(),
                        `log_action` = 'update',
                        `concierge_product_id` = NEW.`concierge_product_id`,
                        `product_id` = NEW.`product_id`,
                        `concierge_value` = NEW.`concierge_value`,
                        `last_updated` = NEW.`last_updated`,
                        `updated_by` = NEW.`updated_by`;
                    END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_update_concierge_product`;;
            ]]>
            </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_concierge_product`;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_delete_concierge_product AFTER DELETE ON concierge_product
                FOR EACH ROW
                BEGIN
                    INSERT INTO `art_relations_log`.`concierge_product_log` SET
                    `log_timestamp` = NOW(),
                    `log_action` = 'delete',
                    `concierge_product_id` = OLD.`concierge_product_id`,
                    `product_id` = OLD.`product_id`,
                    `concierge_value` = OLD.`concierge_value`,
                    `last_updated` = OLD.`last_updated`,
                    `updated_by` = OLD.`updated_by`;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_delete_concierge_product`;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
