<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="ARTARCH_392_backfill_lp_facebook:1" author="gaguirre" run-on-change="true">
        <query>
            CALL apoc.log.info("Starting run of participant_external_link ingest for lsr facebook at %s", [datetime()]);
        </query>
        <query>
            <![CDATA[
                CALL apoc.periodic.iterate(
                    "
                        WITH 'mysql_artrelations' as url_alias,
                        '
                            SELECT
                                pel.label_participant_id,
                                pel.store_artist_id,
                                pel.store_id
                            FROM participant_external_link pel
                            WHERE pel.store_id = 1173 AND pel.store_artist_id IS NOT NULL
                            AND pel.store_artist_id != \\'\\'
                        ' as sql
                        CALL apoc.load.jdbc(url_alias, sql)
                        YIELD row
                        RETURN row
                    ",
                    "
                        MATCH (lp:LabelParticipant {id: toInteger(row.label_participant_id)})
                        SET
                            lp.facebookId = apoc.text.replace(toString(row.store_artist_id), 'profile.php\\\\?id=', ''),
                            lp.modifiedAt = datetime()
                    ",
                    {batchSize:1000, iterateList:true, parallel:true}
                );
            ]]>
        </query>
        <query>
            CALL apoc.log.info("Finished participant_external_link ingest for lsr facebook at %s", [datetime()]);
        </query>
    </changeset>
</changelog>
