<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/var/app/InputFileSchema.xsd">

    <!-- 93 release_artist_neo4j_only -->
    <changeset id="KDH-440-DELETE_release_artist_neo4j_only" author="npatel" neo4j-server="music-graph" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
                    SELECT id as release_artist_id, role, product_id as release_id
                    FROM facts.prod.release_artist 
                    WHERE id IN (
                            3691661, 9404552, 9460764, 9390335, 9445899, 9460763, 7356564, 10219206, 9388252, 9454381, 9468107, 7321534, 6571959, 9461396, 9467352, 11136962, 10865517, 9461245, 9456236, 9445898, 9387402, 6642420, 7309776, 9461469, 9461982, 6921327, 7036165, 9421797, 9279742, 9421798, 7315355, 9465660, 6729904, 9390368, 9455216, 9455219, 9461951, 9389171, 7209971, 9456761, 9455218, 9327593, 9387404, 3691662, 9469640, 9390370, 9455848, 9455248, 9457422, 9459225, 9390369, 9327631, 9403570, 7218936, 9454939, 6596622, 9367253, 6764432, 9466000, 9457442, 8586857, 9468105, 9460765, 9449859, 9423088, 7338174, 6550759, 6712658, 7218935, 9461279, 9384869, 9459236, 9457143, 9436195, 9469116, 9421799, 9425066, 9461983, 9387403, 9384868, 9390361, 12954212, 9421796, 9455215, 3691660, 10948582, 6642419, 9455217, 9455829, 6535576, 9461984, 9390336, 9436196
                    );
                ]]>
            </sqlquery>
        </precondition>
        
    <!-- same as /lambda-kinesis-to-neo4j/blob/master/lambda/kinesis-to-neo4j/src/logic/art_relations/queries/queries.py#L1195 but with event. prefix -->
        <cypherquery>
            <![CDATA[
                MATCH (ra:ReleaseArtist {id: toInteger(event.RELEASE_ARTIST_ID)})
                MATCH (ra)-[:CREATED_FROM]-(lp:LabelParticipant)
                OPTIONAL MATCH (lp)-[pi:PARTICIPATED_IN {participated_as: event.ROLE}]-
                    (p:Product {id: toInteger(event.RELEASE_ID)})
                WITH *, [node IN [ra, lp, p] WHERE node IS NOT NULL] AS nodesToLock
                CALL apoc.lock.nodes(nodesToLock)
                OPTIONAL MATCH (lp)-[:CREATED_FROM]-(sameRa:ReleaseArtist {role: event.ROLE, productId: toInteger(event.RELEASE_ID)})
                    WHERE sameRa.id <> event.RELEASE_ARTIST_ID
                FOREACH (noDup IN CASE WHEN sameRa IS NULL THEN [1] ELSE [] END |
                    DETACH DELETE pi, ra
                )
                FOREACH (dup IN CASE WHEN sameRa IS NOT NULL THEN [1] ELSE [] END |
                    DETACH DELETE ra
                )
            ]]>
        </cypherquery>
    </changeset>
</changelog>
