<?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="schauhan">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE `art_relations`;;

                DROP TRIGGER IF EXISTS `after_delete_product_physical_supply_chain_metadata`;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_delete_product_physical_supply_chain_metadata AFTER DELETE ON product_physical_supply_chain_metadata
                FOR EACH ROW
                BEGIN
                    INSERT INTO `art_relations_log`.`product_physical_supply_chain_metadata_log` SET
                    `log_timestamp` = NOW(),
                    `log_action` = 'delete',
                    `id` = OLD.`id`,
                    `product_id` = OLD.`product_id`,
                    `store_id`= OLD.`store_id`,
                    `embargo_date` = OLD.`embargo_date`,
                    `release_date` = OLD.`release_date`,
                    `sale_start_date` = OLD.`sale_start_date`,
                    `date_added` = OLD.`date_added`,
                    `date_updated` = OLD.`date_updated`;
                END
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS `after_delete_product_physical_supply_chain_metadata`;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="2" author="schauhan">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_insert_product_physical_supply_chain_metadata;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_product_physical_supply_chain_metadata AFTER INSERT ON product_physical_supply_chain_metadata
                FOR EACH ROW 
                BEGIN
                    INSERT INTO `art_relations_log`.`product_physical_supply_chain_metadata_log` SET
                    `log_timestamp` = NOW(),
                    `log_action` = 'insert',
                    `id` = NEW.`id`,
                    `product_id` = NEW.`product_id`,
                    `store_id`= NEW.`store_id`,
                    `embargo_date` = NEW.`embargo_date`,
                    `release_date` = NEW.`release_date`,
                    `sale_start_date` = NEW.`sale_start_date`,
                    `date_added` = NEW.`date_added`,
                    `date_updated` = NEW.`date_updated`;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                <![CDATA[
                    USE art_relations;;
                    DROP TRIGGER IF EXISTS after_insert_product_physical_supply_chain_metadata;;
                ]]>
            </sql>
        </rollback>
    </changeSet>
        <changeSet id="3" author="schauhan">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_update_product_physical_supply_chain_metadata;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_update_product_physical_supply_chain_metadata AFTER UPDATE ON product_physical_supply_chain_metadata
                FOR EACH ROW 
                BEGIN
                    INSERT INTO `art_relations_log`.`product_physical_supply_chain_metadata_log` SET
                    `log_timestamp` = NOW(),
                    `log_action` = 'update',
                    `id` = NEW.`id`,
                    `product_id` = NEW.`product_id`,
                    `store_id`= NEW.`store_id`,
                    `embargo_date` = NEW.`embargo_date`,
                    `release_date` = NEW.`release_date`,
                    `sale_start_date` = NEW.`sale_start_date`,
                    `date_added` = NEW.`date_added`,
                    `date_updated` = NEW.`date_updated`;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                <![CDATA[
                    USE art_relations;;
                    DROP TRIGGER IF EXISTS after_update_product_physical_supply_chain_metadata;;
                ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
