<?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;;
            
            DROP TABLE IF EXISTS `ROLLBACK-DIG-2933-us_publishing_obligation_Y`;;
            
            CREATE TABLE `ROLLBACK-DIG-2933-us_publishing_obligation_Y`
            SELECT t.id, t.us_publishing_obligation
            FROM track t
            INNER JOIN releases r ON r.upc = t.upc
            WHERE t.third_party_publisher = 'Y'
            AND r.release_status = 'label_processing'
            AND (t.us_publishing_obligation IS NULL OR t.us_publishing_obligation = '');;
            
            UPDATE track AS t
            INNER JOIN releases r ON r.upc = t.upc
                SET t.us_publishing_obligation = 'Composition'
            WHERE t.third_party_publisher = 'Y'
            AND r.release_status = 'label_processing'
            AND (t.us_publishing_obligation IS NULL OR t.us_publishing_obligation = '');;
            
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;
                
                UPDATE track t
                INNER JOIN `ROLLBACK-DIG-2933-us_publishing_obligation_Y` rb ON rb.id = t.id
                    SET t.us_publishing_obligation = rb.us_publishing_obligation;;
                    
                DROP TABLE IF EXISTS `ROLLBACK-DIG-2933-us_publishing_obligation_Y`;;
                    
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="2" author="pshrivastava">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            USE art_relations;;
            
            DROP TABLE IF EXISTS `ROLLBACK-DIG-2933-us_publishing_obligation_N`;;
            
            CREATE TABLE `ROLLBACK-DIG-2933-us_publishing_obligation_N`
            SELECT t.id, t.us_publishing_obligation
            FROM track t
            INNER JOIN releases r ON r.upc = t.upc
            WHERE t.third_party_publisher = 'N'
            AND r.release_status = 'label_processing'
            AND (t.us_publishing_obligation IS NULL OR t.us_publishing_obligation = '');;
            
            UPDATE track AS t
            INNER JOIN releases r ON r.upc = t.upc
                SET t.us_publishing_obligation = 'ControlledByYourLabel'
            WHERE t.third_party_publisher = 'N'
            AND r.release_status = 'label_processing'
            AND (t.us_publishing_obligation IS NULL OR t.us_publishing_obligation = '');;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;
                
                UPDATE track t
                INNER JOIN `ROLLBACK-DIG-2933-us_publishing_obligation_N` rb ON rb.id = t.id
                    SET t.us_publishing_obligation = rb.us_publishing_obligation;;
                    
                DROP TABLE IF EXISTS `ROLLBACK-DIG-2933-us_publishing_obligation_N`;;
            </sql>
        </rollback>
    </changeSet>    
</databaseChangeLog>
