<?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_lp_to_project:1" author="gaguirre" run-on-change="true">
        <query>
            CALL apoc.periodic.iterate(
                'MATCH(pr:Project)-[:HAS_ARTIST]->(ai:ArtistInfo) RETURN pr, ai',
                'MERGE (i:IncrementId {nodeName: "LabelParticipant"})
                    ON CREATE SET i.id = 1
                    ON MATCH SET i.id = i.id + 1
                MERGE (lp:LabelParticipant {
                    vendorId: pr.vendorId,
                    subaccountId: pr.subaccountId,
                    name: trim(apoc.text.regreplace(ai.name, "[ ]{2,}", " "))
                })
                ON CREATE SET
                    lp.id = i.id,
                    lp.uuid = apoc.create.uuid()
                MERGE (lp)-[:CREATED_FROM]->(ai)
                MERGE (pr)-[:CREATED_FOR_PARTICIPANT]->(lp)',
                {batchSize:1000, iterateList:true, parallel:true}
            );
        </query>
    </changeset>
</changelog>
