<?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="tnozhkina">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
            USE art_relations;;
            DROP TRIGGER IF EXISTS after_insert_subaccount;;
            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_subaccount AFTER INSERT ON subaccount FOR EACH ROW
            BEGIN
                CALL cloudsearch.sp_upsert_subaccount(NEW.subaccount_id);
                INSERT INTO art_relations_log.subaccount_log SET
                    log_timestamp = NOW(),
                    log_action = 'insert',
                    subaccount_id = NEW.subaccount_id,
                    vendor_id = NEW.vendor_id,
                    subaccount_uuid = NEW.subaccount_uuid,
                    subaccount_name = NEW.subaccount_name,
                    genre_id = NEW.genre_id,
                    website_url = NEW.website_url,
                    myspace_url = NEW.myspace_url,
                    city = NEW.city,
                    state_province = NEW.state_province,
                    other_state = NEW.other_state,
                    country_id = NEW.country_id,
                    description = NEW.description,
                    commission_override = NEW.commission_override,
                    date_deleted = NEW.date_deleted,
                    date_created = NEW.date_created,
                    last_updated = NEW.last_updated,
                    subaccount_split_type = NEW.subaccount_split_type;
            END;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_insert_subaccount;;
                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_insert_subaccount AFTER INSERT ON subaccount FOR EACH ROW
                BEGIN
                    CALL cloudsearch.sp_upsert_subaccount(NEW.subaccount_id);
                END;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="2" author="tnozhkina">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
            DROP TRIGGER IF EXISTS after_update_subaccount;;
            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_update_subaccount AFTER UPDATE ON subaccount FOR EACH ROW
            BEGIN
                CALL cloudsearch.sp_upsert_subaccount(NEW.subaccount_id);
                INSERT INTO art_relations_log.subaccount_log SET
                    log_timestamp = NOW(),
                    log_action = 'update',
                    subaccount_id = NEW.subaccount_id,
                    vendor_id = NEW.vendor_id,
                    subaccount_uuid = NEW.subaccount_uuid,
                    subaccount_name = NEW.subaccount_name,
                    genre_id = NEW.genre_id,
                    website_url = NEW.website_url,
                    myspace_url = NEW.myspace_url,
                    city = NEW.city,
                    state_province = NEW.state_province,
                    other_state = NEW.other_state,
                    country_id = NEW.country_id,
                    description = NEW.description,
                    commission_override = NEW.commission_override,
                    date_deleted = NEW.date_deleted,
                    date_created = NEW.date_created,
                    last_updated = NEW.last_updated,
                    subaccount_split_type = NEW.subaccount_split_type;
            END;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                <![CDATA[
                DROP TRIGGER IF EXISTS after_update_subaccount;;
                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_update_subaccount AFTER UPDATE ON subaccount FOR EACH ROW
                BEGIN
                    CALL cloudsearch.sp_upsert_subaccount(NEW.subaccount_id);
                END;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
    <changeSet id="3" author="tnozhkina">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            <![CDATA[
            USE art_relations;;
            DROP TRIGGER IF EXISTS after_delete_subaccount;;
            CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_delete_subaccount AFTER DELETE ON subaccount FOR EACH ROW
            BEGIN
                CALL cloudsearch.sp_upsert_subaccount(OLD.subaccount_id);
                INSERT INTO art_relations_log.subaccount_log SET
                    log_timestamp = NOW(),
                    log_action = 'delete',
                    subaccount_id = OLD.subaccount_id,
                    vendor_id = OLD.vendor_id,
                    subaccount_uuid = OLD.subaccount_uuid,
                    subaccount_name = OLD.subaccount_name,
                    genre_id = OLD.genre_id,
                    website_url = OLD.website_url,
                    myspace_url = OLD.myspace_url,
                    city = OLD.city,
                    state_province = OLD.state_province,
                    other_state = OLD.other_state,
                    country_id = OLD.country_id,
                    description = OLD.description,
                    commission_override = OLD.commission_override,
                    date_deleted = OLD.date_deleted,
                    date_created = OLD.date_created,
                    last_updated = OLD.last_updated,
                    subaccount_split_type = OLD.subaccount_split_type;
            END;;
        ]]>
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                <![CDATA[
                USE art_relations;;
                DROP TRIGGER IF EXISTS after_delete_subaccount;;
                CREATE DEFINER = 'theorchard'@'10.10.%' TRIGGER after_delete_subaccount AFTER DELETE ON subaccount FOR EACH ROW
                BEGIN
                    CALL cloudsearch.sp_upsert_subaccount(OLD.subaccount_id);
                END;;
            ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
