<?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="pshrivastava">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            USE art_relations;;

            DROP TRIGGER IF EXISTS after_update_upcs;;

            CREATE DEFINER='theorchard'@'10.10.%' TRIGGER after_update_upcs AFTER UPDATE ON upcs
            FOR EACH ROW
            BEGIN
                INSERT INTO art_relations_log.upcs_log SET
                    log_date_utc = UTC_TIMESTAMP(),
                    log_action   = 'update',
                    upc          = NEW.upc,
                    status       = NEW.status,
                    last_updated = NEW.last_updated
                ;
            END;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;

                DROP TRIGGER IF EXISTS after_update_upcs;;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
