<?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-276_backfill_artist_info:1" author="gaguirre" run-on-change="true">
        <query>
            CALL apoc.periodic.iterate(
                "
                    WITH 'mysql_artrelations' as url_alias,
                    '
                        SELECT artist_id, name, vendor_id
                        FROM artist_info
                    ' as sql
                    CALL apoc.load.jdbc(url_alias, sql)
                    YIELD row
                    RETURN row
                ",
                "
                    MERGE (ai:ArtistInfo {id: toInteger(row.artist_id)})
                    SET ai.name = row.name,
                        ai.vendorId = toInteger(row.vendor_id),
                        ai.updated_at = datetime()
                ",
                {batchSize:1000}
            );
        </query>
        <query>
            MATCH(ai:ArtistInfo) WHERE ai.name IS NULL
            DETACH DELETE ai
        </query>
    </changeset>
</changelog>
