<?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="n-kumar">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">

        <!--Insert new asset type for S8 Image-->
            INSERT INTO asset_type (asset, file_type, extension, initial_folder, folder_structure) 
            VALUES ("video_image_S8", "file", ".tif", "img/TIF/", "{upc(0,6)}/{upc(6,3)}/{upc}_S8.tif");;

        <!--retrieve newly inserted asset type id-->
            SELECT @newAssetTypeId:=LAST_INSERT_ID();;

        <!--retrieve asset type id of an already existing video image asset type -->
            SELECT @existingAssetTypeId:=asset_type_id FROM asset_type WHERE asset="video_image_S7";;

        <!--Copying identical storage locations for an existing video image format to the newly created one -->
            INSERT INTO storage_drive_asset_folder(storage_drive_id,asset_type_id,initial_folder)
            SELECT storage_drive_id, @newAssetTypeId, initial_folder FROM storage_drive_asset_folder 
            WHERE asset_type_id=@existingAssetTypeId;;

        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">

            <!--rollback for S8 Image asset-->
            DELETE sf.* FROM storage_drive_asset_folder sf 
            INNER JOIN asset_type a ON a.asset_type_id = sf.asset_type_id WHERE a.asset = "video_image_S8";;

            DELETE FROM asset_type WHERE asset = "video_image_S8";;

            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
