<?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">
            INSERT INTO vendor_dms_master_restriction(customer_master_master_id, distribution_type_id, vendor_contract_id)
            SELECT cmmdt.customer_master_master_id, vcdt.distribution_type_id, vcdt.vendor_contract_id 
            FROM vendor_contract_distribution_type vcdt
            INNER JOIN customer_master_master_distribution_type cmmdt ON cmmdt.distribution_type_id = vcdt.distribution_type_id
            LEFT JOIN vendor_dms_master_restriction vdmr ON vdmr.customer_master_master_id = cmmdt.customer_master_master_id 
                AND vdmr.distribution_type_id = cmmdt.distribution_type_id
                AND vdmr.vendor_contract_id = vcdt.vendor_contract_id
            WHERE vcdt.new_store_default = 'Y' 
                AND cmmdt.customer_master_master_id = 697
                AND vdmr.restriction_id IS NULL;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                SELECT 'There is no going back!';;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
