<?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">
            USE art_relations;;
            
            CREATE TABLE IF NOT EXISTS `ROLLBACK-update_distribution_format_id`
            SELECT t.upc
            FROM track t 
            INNER JOIN releases r ON t.upc = r.upc 
            WHERE t.track_type = 'video' AND r.distribution_format_id = 1 AND r.format = 'single'
            GROUP BY t.upc;;

            UPDATE releases r
            INNER JOIN `ROLLBACK-update_distribution_format_id` rb ON rb.upc = r.upc
            SET r.distribution_format_id = 57;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;

                UPDATE releases r
                INNER JOIN `ROLLBACK-update_distribution_format_id` rb ON rb.upc = r.upc
                SET r.distribution_format_id = 1;;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
