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

            DROP TRIGGER IF EXISTS after_insert_artist;;

            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_artist AFTER INSERT ON artist_info
            FOR EACH ROW
            BEGIN
                CALL cloudsearch.sp_upsert_artist(NEW.artist_id);
                
                INSERT INTO art_relations_log.artist_info_log 
                SET log_timestamp = NOW(),
                    log_action = 'insert',
                    artist_id = NEW.artist_id,
                    `url` = NEW.`url`,
                    when_entered = NEW.when_entered,
                    entered_by = NEW.entered_by,
                    description = NEW.description,
                    name = NEW.name,
                    vendor_id = NEW.vendor_id,
                    last_updated = NEW.last_updated,
                    join_artist_id = NEW.join_artist_id,
                    myspace_url = NEW.myspace_url,
                    myspace_id = NEW.myspace_id,
                    address_city = NEW.address_city,
                    address_state = NEW.address_state,
                    address_other_state = NEW.address_other_state,
                    orchard_country = NEW.orchard_country,
                    active = NEW.active,
                    tms_id = NEW.tms_id,
                    primary_photo_id = NEW.primary_photo_id,
                    address_zip = NEW.address_zip,
                    youtube_mytourdate_url = NEW.youtube_mytourdate_url,
                    twitter_mytourdate_url = NEW.twitter_mytourdate_url,
                    artist_email = NEW.artist_email,
                    artist_type = NEW.artist_type,
                    unique_show_id = NEW.unique_show_id;
            END;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
                USE art_relations;;

                DROP TRIGGER IF EXISTS after_insert_artist;;

                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_artist AFTER INSERT ON artist_info
                FOR EACH ROW
                BEGIN
                    CALL cloudsearch.sp_upsert_artist(NEW.artist_id);

                    INSERT INTO art_relations_log.artist_info_log 
                    SET log_timestamp = NOW(),
                        log_action = 'insert',
                        artist_id = NEW.artist_id,
                        url = NEW.url,
                        when_entered = NEW.when_entered,
                        entered_by = NEW.entered_by,
                        description = NEW.description,
                        name = NEW.name,
                        vendor_id = NEW.vendor_id,
                        last_updated = NEW.last_updated,
                        join_artist_id = NEW.join_artist_id,
                        myspace_url = NEW.myspace_url,
                        myspace_id = NEW.myspace_id,
                        address_city = NEW.address_city,
                        address_state = NEW.address_state,
                        address_other_state = NEW.address_other_state,
                        orchard_country = NEW.orchard_country,
                        active = NEW.active,
                        tms_id = NEW.tms_id,
                        primary_photo_id = NEW.primary_photo_id,
                        address_zip = NEW.address_zip,
                        youtube_mytourdate_url = NEW.youtube_mytourdate_url,
                        twitter_mytourdate_url = NEW.twitter_mytourdate_url,
                        artist_email = NEW.artist_email,
                        artist_type = NEW.artist_type,
                        unique_show_id = NEW.unique_show_id;
                END;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
