<?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, 'K:\\');;
            set @storageDriveId = last_insert_id();;

            insert into storage_drive_asset_folder (storage_drive_id, asset_type_id, initial_folder)
            values (@storageDriveId, 352, 'videomastered_102');;

            update asset a
            inner join asset_location al on a.asset_id = al.asset_id
            inner join storage_drive_asset_folder sdaf on al.storage_drive_id = sdaf.storage_drive_id 
                and a.asset_type_id = sdaf.asset_type_id
            set al.storage_drive_id = @storageDriveId
            where al.storage_drive_id = 274 and sdaf.asset_type_id = 352;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE direct_delivery;;

                select storage_drive_id into @storageDriveId_new
                from storage_drive_asset_folder 
                where asset_type_id = 352 and initial_folder = 'videomastered_102';;

                select storage_drive_id into @storageDriveId_old
                from storage_drive_asset_folder
                where asset_type_id = 352 and initial_folder = 'videomastered_18';;

                update asset a
                inner join asset_location al on a.asset_id = al.asset_id
                inner join storage_drive_asset_folder sdaf on al.storage_drive_id = sdaf.storage_drive_id
                    and a.asset_type_id = sdaf.asset_type_id
                set al.storage_drive_id = @storageDriveId_old
                where al.storage_drive_id = @storageDriveId_new and sdaf.asset_type_id = 352;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
