<?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="101" author="jian">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            DROP PROCEDURE IF EXISTS sp_write_vendor_release_identifier_from_grid;;

            CREATE DEFINER='theorchard'@'10.10.%' PROCEDURE sp_write_vendor_release_identifier_from_grid(
                    IN in_release_id INT UNSIGNED,
                    IN in_upc BIGINT UNSIGNED,
                    IN in_product_no CHAR(14)
                )
            BEGIN
                    UPDATE releases
                    SET vendor_release_identifier = in_product_no
                    WHERE release_id = in_release_id
                    AND (
                        vendor_release_identifier IS NULL OR
                        vendor_release_identifier = ''
                    );
            END;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                DROP PROCEDURE IF EXISTS sp_write_vendor_release_identifier_from_grid;;

                CREATE DEFINER='theorchard'@'10.10.%' PROCEDURE sp_write_vendor_release_identifier_from_grid(
                    IN in_release_id INT UNSIGNED,
                    IN in_upc BIGINT UNSIGNED,
                    IN in_product_no CHAR(14)
                )
                BEGIN
                    UPDATE releases
                    SET vendor_release_identifier = in_product_no
                    WHERE release_id = in_release_id
                    AND upc = in_upc
                    AND (
                        vendor_release_identifier IS NULL OR
                        vendor_release_identifier = ''
                    );
                END;;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
