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

            DROP TRIGGER IF EXISTS  `after_update_release_subgenre`;;

            CREATE DEFINER=`theorchard`@`10.10.%` TRIGGER `after_update_release_subgenre` AFTER UPDATE ON `release_subgenre` 
            FOR EACH ROW BEGIN
                INSERT INTO art_relations_log.release_subgenre_log SET
                    log_timestamp = NOW(),
                    log_action    = 'update',
                    id            = NEW.id,
                    release_id    = NEW.release_id,
                    upc           = NEW.upc,
                    subgenre_id   = NEW.subgenre_id;

                IF (OLD.subgenre_id <> NEW.subgenre_id) THEN
                    CALL art_relations.sp_insert_product_physical_reports_change_history(NEW.release_id, 'subgenre');
                END IF;
            END;;
        ]]>

        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE `art_relations`;;

                DROP TRIGGER IF EXISTS  `after_update_release_subgenre`;;

                CREATE DEFINER=`theorchard`@`10.10.%` TRIGGER `after_update_release_subgenre` AFTER UPDATE ON `release_subgenre` 
                FOR EACH ROW BEGIN
                    INSERT INTO art_relations_log.release_subgenre_log SET
                        log_timestamp = NOW(),
                        log_action    = 'update',
                        id            = NEW.id,
                        release_id    = NEW.release_id,
                        upc           = NEW.upc,
                        subgenre_id   = NEW.subgenre_id;
                END;;
            ]]>

            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
