<?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">
        <![CDATA[
            USE direct_delivery;;
            
            DROP PROCEDURE IF EXISTS sp_get_priorities;;

            CREATE DEFINER='theorchard_dd'@'127.0.0.1' PROCEDURE sp_get_priorities(IN eqd_id INT)
            BEGIN
                SELECT eqd.encoding_queue_detail_id, jp.priority AS encoding_order_priority, cmm.priority AS store_priority
                FROM encoding_queue eq
                INNER JOIN encoding_queue_detail eqd ON eq.encoding_queue_id = eqd.encoding_queue_id
                INNER JOIN customer_master_master cmm ON cmm.customer_master_master_id = eqd.dms_master_master_id
                INNER JOIN job_priority jp ON jp.encoding_queue_detail_id = eqd.encoding_queue_detail_id
                WHERE eqd.encoding_queue_detail_id = eqd_id;
            END;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
            USE direct_delivery;;
            
            DROP PROCEDURE IF EXISTS sp_get_priorities;;

            CREATE DEFINER='theorchard_dd'@'127.0.0.1' PROCEDURE sp_get_priorities(IN eqd_id INT)
            BEGIN
                SELECT eqd.encoding_queue_detail_id, eq.priority AS encoding_order_priority, cmm.priority AS store_priority
                FROM encoding_queue eq
                INNER JOIN encoding_queue_detail eqd ON eq.encoding_queue_id = eqd.encoding_queue_id
                INNER JOIN customer_master_master cmm ON cmm.customer_master_master_id = eqd.dms_master_master_id
                WHERE eqd.encoding_queue_detail_id = eqd_id;
            END;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
