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

            set @storageId = 51;;

            insert into storage_drive (storage_id, drive_location) values (@storageId, 'L:\\');;
            set @storageLDriveId = last_insert_id();;

            insert into storage_drive_asset_folder (storage_drive_id, asset_type_id, initial_folder)
            select @storageLDriveId, asset_type_id, replace(initial_folder, 101, 103) 
            from storage_drive_asset_folder where asset_type_id not in (352) and storage_drive_id = 316;;

            insert into storage_drive (storage_id, drive_location) values (@storageId, 'M:\\');;
            set @storageMDriveId = last_insert_id();;
            
            insert into storage_drive_asset_folder (storage_drive_id, asset_type_id, initial_folder)
            select @storageMDriveId, asset_type_id, replace(initial_folder, 101, 104) 
            from storage_drive_asset_folder where asset_type_id not in (352) and storage_drive_id = 316;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE direct_delivery;;

                select storage_drive_id into @storageLDriveId
                from storage_drive_asset_folder 
                where asset_type_id = 1 and initial_folder = 'WAV103';;

                delete from storage_drive_asset_folder 
                where storage_drive_id = @storageLDriveId;;

                select storage_drive_id into @storageMDriveId
                from storage_drive_asset_folder
                where asset_type_id = 1 and initial_folder = 'WAV104';;

                delete from storage_drive_asset_folder                                  
                where storage_drive_id = @storageMDriveId;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
