<?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="ssavva" runOnChange="true">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;

                DROP TRIGGER IF EXISTS after_insert_product_video;;

                CREATE DEFINER = theorchard@`10.10.%` TRIGGER after_insert_product_video
                    AFTER INSERT
                    ON product_video
                    FOR EACH ROW
                BEGIN
                    INSERT INTO art_relations_log.product_video_log
                        SET log_timestamp = NOW(),
                            log_action = 'insert',
                            id = NEW.id,
                            release_id = NEW.release_id,
                            type_of_video = NEW.type_of_video,
                            language_of_video_title = NEW.language_of_video_title,
                            video_title = NEW.video_title,
                            description = NEW.description,
                            version = NEW.version,
                            product_code = NEW.product_code,
                            upc = NEW.upc,
                            isrc = NEW.isrc,
                            imprint = NEW.imprint,
                            parental_advisory = NEW.parental_advisory,
                            language_of_video_content = NEW.language_of_video_content,
                            lyrics = NEW.lyrics,
                            c_line_year = NEW.c_line_year,
                            c_line_copyright_holder = NEW.c_line_copyright_holder,
                            p_line_year = NEW.p_line_year,
                            p_line_copyright_holder = NEW.p_line_copyright_holder,
                            new_release = NEW.new_release,
                            original_release_date = NEW.original_release_date,
                            release_date = NEW.release_date,
                            special_instructions = NEW.special_instructions,
                            deliver_to_all = NEW.deliver_to_all,
                            genre_id = NEW.genre_id,
                            subgenre_id = NEW.subgenre_id,
                            contributors = NEW.contributors,
                            keywords = NEW.keywords,
                            primary_artist_id = NEW.primary_artist_id,
                            latest_pipeline_run_id = NEW.latest_pipeline_run_id,
                            preview_start_time = NEW.preview_start_time,
                            thumbnail_path = NEW.thumbnail_path,
                            channel_selection = NEW.channel_selection,
                            not_for_distribution = NEW.not_for_distribution,
                            vevo_controlled = NEW.vevo_controlled,
                            updated_at = NEW.updated_at,
                            created_at = NEW.created_at,
                            submitted_at = NEW.submitted_at,
                            youtube_only = NEW.youtube_only,
                            ingest_filename = NEW.ingest_filename,
                            custom_thumbnail_path = NEW.custom_thumbnail_path,
                            migrated_metadata_at = NEW.migrated_metadata_at,
                            migrated_asset_at = NEW.migrated_asset_at,
                            associated_track_id = NEW.associated_track_id,
                            prores_path = NEW.prores_path,
                            h264_path = NEW.h264_path;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_insert_product_video;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="2" author="ssavva" runOnChange="true">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;

                DROP TRIGGER IF EXISTS after_update_product_video;;

                CREATE DEFINER = theorchard@`10.10.%` TRIGGER after_update_product_video
                    AFTER UPDATE
                    ON product_video
                    FOR EACH ROW
                BEGIN
                    INSERT INTO art_relations_log.product_video_log
                        SET log_timestamp = NOW(),
                            log_action = 'update',
                            id = NEW.id,
                            release_id = NEW.release_id,
                            type_of_video = NEW.type_of_video,
                            language_of_video_title = NEW.language_of_video_title,
                            video_title = NEW.video_title,
                            description = NEW.description,
                            version = NEW.version,
                            product_code = NEW.product_code,
                            upc = NEW.upc,
                            isrc = NEW.isrc,
                            imprint = NEW.imprint,
                            parental_advisory = NEW.parental_advisory,
                            language_of_video_content = NEW.language_of_video_content,
                            lyrics = NEW.lyrics,
                            c_line_year = NEW.c_line_year,
                            c_line_copyright_holder = NEW.c_line_copyright_holder,
                            p_line_year = NEW.p_line_year,
                            p_line_copyright_holder = NEW.p_line_copyright_holder,
                            new_release = NEW.new_release,
                            original_release_date = NEW.original_release_date,
                            release_date = NEW.release_date,
                            special_instructions = NEW.special_instructions,
                            deliver_to_all = NEW.deliver_to_all,
                            genre_id = NEW.genre_id,
                            subgenre_id = NEW.subgenre_id,
                            contributors = NEW.contributors,
                            keywords = NEW.keywords,
                            primary_artist_id = NEW.primary_artist_id,
                            latest_pipeline_run_id = NEW.latest_pipeline_run_id,
                            preview_start_time = NEW.preview_start_time,
                            thumbnail_path = NEW.thumbnail_path,
                            channel_selection = NEW.channel_selection,
                            not_for_distribution = NEW.not_for_distribution,
                            vevo_controlled = NEW.vevo_controlled,
                            updated_at = NEW.updated_at,
                            created_at = NEW.created_at,
                            submitted_at = NEW.submitted_at,
                            youtube_only = NEW.youtube_only,
                            ingest_filename = NEW.ingest_filename,
                            custom_thumbnail_path = NEW.custom_thumbnail_path,
                            migrated_metadata_at = NEW.migrated_metadata_at,
                            migrated_asset_at = NEW.migrated_asset_at,
                            associated_track_id = NEW.associated_track_id,
                            prores_path = NEW.prores_path,
                            h264_path = NEW.h264_path;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_update_product_video;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="3" author="ssavva" runOnChange="true">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;

                DROP TRIGGER IF EXISTS after_delete_product_video;;

                CREATE DEFINER = theorchard@`10.10.%` TRIGGER after_delete_product_video
                    AFTER DELETE
                    ON product_video
                    FOR EACH ROW
                BEGIN
                    INSERT INTO art_relations_log.product_video_log
                        SET log_timestamp = NOW(),
                            log_action = 'delete',
                            id = OLD.id,
                            release_id = OLD.release_id,
                            type_of_video = OLD.type_of_video,
                            language_of_video_title = OLD.language_of_video_title,
                            video_title = OLD.video_title,
                            description = OLD.description,
                            version = OLD.version,
                            product_code = OLD.product_code,
                            upc = OLD.upc,
                            isrc = OLD.isrc,
                            imprint = OLD.imprint,
                            parental_advisory = OLD.parental_advisory,
                            language_of_video_content = OLD.language_of_video_content,
                            lyrics = OLD.lyrics,
                            c_line_year = OLD.c_line_year,
                            c_line_copyright_holder = OLD.c_line_copyright_holder,
                            p_line_year = OLD.p_line_year,
                            p_line_copyright_holder = OLD.p_line_copyright_holder,
                            new_release = OLD.new_release,
                            original_release_date = OLD.original_release_date,
                            release_date = OLD.release_date,
                            special_instructions = OLD.special_instructions,
                            deliver_to_all = OLD.deliver_to_all,
                            genre_id = OLD.genre_id,
                            subgenre_id = OLD.subgenre_id,
                            contributors = OLD.contributors,
                            keywords = OLD.keywords,
                            primary_artist_id = OLD.primary_artist_id,
                            latest_pipeline_run_id = OLD.latest_pipeline_run_id,
                            preview_start_time = OLD.preview_start_time,
                            thumbnail_path = OLD.thumbnail_path,
                            channel_selection = OLD.channel_selection,
                            not_for_distribution = OLD.not_for_distribution,
                            vevo_controlled = OLD.vevo_controlled,
                            updated_at = OLD.updated_at,
                            created_at = OLD.created_at,
                            submitted_at = OLD.submitted_at,
                            youtube_only = OLD.youtube_only,
                            ingest_filename = OLD.ingest_filename,
                            custom_thumbnail_path = OLD.custom_thumbnail_path,
                            migrated_metadata_at = OLD.migrated_metadata_at,
                            migrated_asset_at = OLD.migrated_asset_at,
                            associated_track_id = OLD.associated_track_id,
                            prores_path = OLD.prores_path,
                            h264_path = OLD.h264_path;
                END;;
            ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_delete_product_video;;
            ]]>
            </sql>
        </rollback>
    </changeSet>

</databaseChangeLog>
