<?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_insert_product_physical;;

            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_physical_product AFTER INSERT ON product_physical
            FOR EACH ROW
            BEGIN
                INSERT INTO art_relations_log.product_physical_log SET
                    log_timestamp    = NOW(),
                    log_action       = 'insert',
                    id               = NEW.id,
                    release_id       = NEW.release_id,
                    packaging_id     = NEW.packaging_id,
                    exclusive_for    = NEW.exclusive_for,
                    initial_stock    = NEW.initial_stock,
                    box_lot          = NEW.box_lot,
                    pricing          = NEW.pricing,
                    end_date         = NEW.end_date,
                    discount         = NEW.discount,
                    individual       = NEW.individual,
                    explicit         = NEW.explicit,
                    exportable       = NEW.exportable,
                    units_per_set    = NEW.units_per_set,
                    wholesale_price  = NEW.wholesale_price
                ;
            END;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_insert_product_physical;;
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="2" author="pshrivastava">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">	
            USE art_relations;;
            DROP TRIGGER IF EXISTS after_update_product_physical;;

            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_update_product_physical AFTER UPDATE ON product_physical
            FOR EACH ROW
            BEGIN
                INSERT INTO art_relations_log.product_physical_log SET
                    log_timestamp    = NOW(),
                    log_action       = 'update',
                    id               = NEW.id,
                    release_id       = NEW.release_id,
                    packaging_id     = NEW.packaging_id,
                    exclusive_for    = NEW.exclusive_for,
                    initial_stock    = NEW.initial_stock,
                    box_lot          = NEW.box_lot,
                    pricing          = NEW.pricing,
                    end_date         = NEW.end_date,
                    discount         = NEW.discount,
                    individual       = NEW.individual,
                    explicit         = NEW.explicit,
                    exportable       = NEW.exportable,
                    units_per_set    = NEW.units_per_set,
                    wholesale_price  = NEW.wholesale_price
                ;
            END;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_update_product_physical;;
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="3" author="pshrivastava">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            USE art_relations;;
            DROP TRIGGER IF EXISTS after_delete_product_physical;;

            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_delete_product_physical AFTER DELETE ON product_physical
            FOR EACH ROW
            BEGIN
                INSERT INTO art_relations_log.product_physical_log SET
                    log_timestamp    = NOW(),
                    log_action       = 'delete',
                    id               = OLD.id,
                    release_id       = OLD.release_id,
                    packaging_id     = OLD.packaging_id,
                    exclusive_for    = OLD.exclusive_for,
                    initial_stock    = OLD.initial_stock,
                    box_lot          = OLD.box_lot,
                    pricing          = OLD.pricing,
                    end_date         = OLD.end_date,
                    discount         = OLD.discount,
                    individual       = OLD.individual,
                    explicit         = OLD.explicit,
                    exportable       = OLD.exportable,
                    units_per_set    = OLD.units_per_set,
                    wholesale_price  = OLD.wholesale_price
                ;
            END;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_delete_product_physical;;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
