<?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="mdadhania">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                DROP TABLE IF EXISTS `ROLLBACK-DIS-3292-product_video_producer_11991`;;

                CREATE TABLE `ROLLBACK-DIS-3292-product_video_producer_11991`
                SELECT r.upc, r.release_id, pv.contributors
                FROM releases r 
                INNER JOIN artist_info ai ON ai.artist_id = r.artist_id
                INNER JOIN product_video pv ON pv.release_id = r.release_id
                WHERE ai.vendor_id = 11991 AND r.product_type_id = 1 AND r.distribution_format_id = 57;;

                UPDATE product_video
                SET `contributors` = REPLACE(`contributors`, ']', ', {"role": "producer", "name": "Hasan Saltık"}]')
                WHERE release_id IN (4473279, 4219671, 4295242, 3915009, 3983977, 3881256, 3533344, 4155654, 4450385, 3904867, 3879967, 3316400, 3316411, 3316338, 3505188, 3885699, 4295357);;

                UPDATE product_video
                SET `contributors` = '[{"role": "producer", "name": "Hasan Saltık"}]'
                WHERE release_id IN (3988474, 4219698, 3316426, 3885708, 3885714, 3955461, 4198734, 3533363, 3875736, 3880028, 3880016, 4154797, 3505184, 3244627, 2063019, 2076659, 2076661, 2076662, 2076663, 2076665, 2076666, 2076668, 2076670, 2076671, 2076672, 2076673, 2076675, 2076677, 2076678, 2076679, 2076680, 2076681, 3875744, 3879952, 4230650, 3316304, 3886871, 3536981, 3875555, 3875566, 3875573, 3254410, 3226983, 3254425, 3254400, 3316327, 3879974, 4168154, 4493436);;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                <![CDATA[
                    UPDATE product_video pv
                    INNER JOIN `ROLLBACK-DIS-3292-product_video_producer_11991` rb ON rb.release_id = pv.release_id
                    SET pv.contributors = rb.contributors;;

                    DROP TABLE `ROLLBACK-DIS-3292-product_video_producer_11991`;;
                ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
