<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="DS-4109_clean_up_project_participant.xml:1" author="savva" run-on-change="true">
        <query>
            <![CDATA[
                MATCH (p:Project)-[r:HAS_ARTIST]->(ai:ArtistInfo)
                WHERE p.artistId <> ai.id
                DELETE r;
            ]]>
        </query>
    </changeset>
    <changeset id="DS-4109_clean_up_project_participant.xml:2" author="savva" run-on-change="true">
        <query>
            <![CDATA[
                MATCH (p:Project)-[r:HAS_ARTIST]->(ai:ArtistInfo)
                WHERE p.vendorId <> ai.vendorId
                DELETE r;
            ]]>
        </query>
    </changeset>
    <changeset id="DS-4109_clean_up_project_participant.xml:3" author="savva" run-on-change="true">
        <query>
            <![CDATA[
                CALL apoc.periodic.iterate(
                    "
                        MATCH (ai:ArtistInfo)<-[:HAS_ARTIST]-(p:Project)-[incorrectCFP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)
                        WHERE NOT (:ArtistInfo)<-[:CREATED_FROM]-(lp) AND ai.name IS NOT NULL
                        MATCH (p)-[:BELONGS_TO]-(v:Vendor)
                        WHERE v.isDistributor <> 'Y'
                        RETURN ai, incorrectCFP, p
                    ",
                    "
                        MATCH (ai)<-[r:CREATED_FROM]-(correctLp:LabelParticipant)
                        DELETE incorrectCFP
                        MERGE (p)-[cfp:CREATED_FOR_PARTICIPANT]->(correctLp)
                        ON CREATE SET
                            cfp.createdAt = datetime(),
                            cfp.createdBy = 'lambda-kinesis-to-neo4j/artist-info-insert-cypher',
                            cfp.lastModifiedAt = datetime(),
                            cfp.lastModifiedBy = 'lambda-kinesis-to-neo4j/artist-info-insert-cypher';
                    ",
                    {batchSize:1000}
                );
            ]]>
        </query>
    </changeset>
</changelog>
