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

    <!-- 256 track_artist_neo4j_only. Using kafka deploy as some of the ids fail in group due to dbms.memory.transaction.max_size threshold -->
    <changeset id="KDH-440-DELETE_track_artist_neo4j_only" author="npatel" neo4j-server="music-graph" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
                    SELECT id, type, track_id 
                    FROM facts.prod.track_artist WHERE id in (
                        102181907, 101991954, 102160395, 102159385, 102181931, 102181927, 102148557, 102160422, 102139211, 102160321, 101962113, 101969997, 102181842, 102160401, 102161337, 102161341, 101942902, 94470481, 102139225, 102139229, 101962153, 101962489, 102182045, 102160326, 102181949, 101962471, 101962484, 102148733, 102181945, 94470480, 101962137, 102161336, 102159393, 102160535, 89787955, 102182042, 94486190, 102161325, 74549938, 102182043, 102139230, 102161063, 102160423, 101656138, 102159361, 101656135, 102040422, 102160887, 101962245, 102160362, 102160363, 94470483, 102160433, 102181933, 101942907, 101962133, 101991949, 102161354, 102160388, 102161060, 102161323, 102171799, 102182047, 101962477, 102139207, 102181921, 102160889, 102170508, 101942904, 102160402, 101962122, 102160270, 102160390, 101656148, 102161061, 101962107, 102160249, 101962117, 74549943, 101962118, 102160365, 102160250, 102160391, 102181915, 102161359, 102181913, 101991951, 102148752, 102160322, 102160279, 102160344, 101942899, 94439393, 101942914, 101969994, 102139206, 102139199, 102181909, 102006879, 102161355, 101991953, 102181943, 101969998, 113519455, 101962127, 102160383, 102161356, 94470482, 101969993, 101991952, 101962480, 102160291, 94439395, 102181935, 101962147, 101942916, 101656146, 102159359, 102148744, 102153944, 102160345, 102160355, 102160328, 101942900, 102181923, 102148725, 102139220, 102139228, 102160354, 102160329, 102117384, 101962102, 102160276, 102160342, 101991950, 97446840, 101962132, 101969996, 102154442, 102160361, 101656139, 102148728, 101962152, 102139221, 102160434, 102161326, 101962112, 74549947, 101942912, 102161339, 74549948, 101656149, 101962490, 102160351, 101962475, 102181929, 102161358, 102160421, 101942901, 102160253, 101962138, 101942905, 102181937, 102160352, 102181951, 101962478, 102160332, 102160252, 74549940, 101942910, 102139215, 102161064, 102160343, 102160251, 102161357, 102139232, 102160294, 101942915, 102160293, 102182044, 102161338, 102160353, 102181941, 102148754, 102160327, 102160289, 101942906, 102161324, 101942911, 101942909, 102160398, 102161340, 74549939, 101962143, 101962486, 102161062, 101962142, 101969995, 102139210, 102040421, 101991956, 102160323, 102181947, 102148644, 102160324, 102160435, 101991955, 101962243, 102160386, 101962128, 101656145, 94403912, 102160272, 102159379, 101962474, 102181939, 101962472, 102160886, 101962123, 101942903, 74549946, 101656136, 94403911, 101942908, 101962481, 101962108, 102160431, 102160290, 102182046, 101991948, 102160888, 102159381, 74549942, 102139198, 102160341, 74549944, 101962485, 101942913, 102161059, 102160292, 101962148, 102161327, 102154446, 102160325, 101962103, 102160274, 102160385, 102183871, 102148573, 102139203, 102160432, 102160885, 101962483, 102044917, 102160364, 101962244
                    )
                    ;
                ]]>
            </sqlquery>
        </precondition>
        
    <!-- same as /lambda-kinesis-to-neo4j/blob/master/lambda/kinesis-to-neo4j/src/logic/art_relations/queries/queries.py#L1469C1-L1469C28 but with event. prefix -->
        <cypherquery>
            <![CDATA[
                MATCH (ta:TrackArtist {id: toInteger(event.ID)})
                MATCH (ta)-[:CREATED_FROM]-(lp:LabelParticipant)
                OPTIONAL MATCH (lp)-[pit:PARTICIPATED_IN {participated_as: event.TYPE}]->
                    (t:Track:Orchard {id: toInteger(event.TRACK_ID)})
                WITH *, [node IN [ta, lp, t] WHERE node IS NOT NULL] AS nodesToLock
                CALL apoc.lock.nodes(nodesToLock)
                OPTIONAL MATCH (lp)-[:CREATED_FROM]-(sameTa:TrackArtist {type: event.TYPE, trackId: toInteger(event.TRACK_ID)})
                WHERE sameTa.id <> toInteger(event.ID)
                FOREACH (noDup IN CASE WHEN sameTa IS NULL THEN [1] ELSE [] END |
                    DETACH DELETE pit, ta
                )
                FOREACH (dup IN CASE WHEN sameTa IS NOT NULL THEN [1] ELSE [] END |
                    DETACH DELETE ta
                )
            ]]>
        </cypherquery>
    </changeset>
</changelog>
