<?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">
            DROP PROCEDURE IF EXISTS `sp_catalog_library_procedure`;;
            
            CREATE PROCEDURE `sp_catalog_library_procedure`()
            BEGIN
            
            CALL sp_insert_catalog_library(@catalogLibraryCnt,@territoryCarveoutCnt,@dmsCarveoutCnt);
                IF @catalogLibraryCnt > 0 THEN
                    CALL sp_update_label_split();
                    CALL sp_update_catalog_library();
                END IF;
                IF @territoryCarveoutCnt > 0 THEN
                    CALL sp_update_territory_carveouts();
                END IF;
                IF @dmsCarveoutCnt > 0 THEN
                    CALL sp_update_dms_carveouts();
                END IF;
            END;;
        </sql>
        <rollback>
	    <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
	        DROP PROCEDURE IF EXISTS sp_catalog_library_procedure ;;
	        
	        CREATE PROCEDURE `sp_catalog_library_procedure`()
	        BEGIN
	        
	        CALL sp_insert_catalog_library(@catalogLibraryCnt,@territoryCarveoutCnt,@dmsCarveoutCnt);
	            IF @catalogLibraryCnt > 0 THEN
	                CALL sp_update_label_split();
	            END IF;
	            IF @territoryCarveoutCnt > 0 THEN
	                CALL sp_update_territory_carveouts();
	            END IF;
	            IF @dmsCarveoutCnt > 0 THEN
	                CALL sp_update_dms_carveouts();
	            END IF;
	        END;;
	    </sql>            
        </rollback>
    </changeSet>
</databaseChangeLog>
