<?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="int1088-neo4j-link-14133-Baga-Biga-artist-profile-spotify-apple-after-d3-conversion:1" author="nlichtenstein" run-on-change="true">
        <query>
            <![CDATA[
                MATCH (v:Vendor)<-[:BELONGS_TO]-(pr:Project)
                WHERE v.id IN [14133]
                CALL apoc.cypher.runMany(
                "
                    // LabelParticipant -> GlobalParticipant
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)<-[gpToLp]-(gp:GlobalParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp)
                    YIELD rel AS rel
                    return true;
                    // Delete LabelParticipant -> GlobalParticipant
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)<-[gpToLp]-(gp:GlobalParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    DELETE gpToLp;
                    // Delete old Product LP -> ArtistInfo
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    DELETE cf;
                    // LabelParticipant -> Track
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(lpToT), {participated_as: lpToT.participated_as}, lpToT, t)
                    YIELD rel AS rel1
                    return true;
                    // LabelParticipant -> TrackArtist
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MATCH (lp)-[cf:CREATED_FROM]->(ta:TrackArtist)<-[:HAS_SOURCE_ARTIST]-(t)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, ta)
                    YIELD rel AS rel
                    return true;
                    // LabelParticipant -> TrackWriter
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MATCH (lp)-[cf:CREATED_FROM]->(tw:TrackWriter)<-[:HAS_SOURCE_ARTIST]-(t)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, tw)
                    YIELD rel AS rel
                    return true;
                    // Delete old LP -> Trac/TrackArtist/TrackWriter
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    OPTIONAL MATCH (lp)-[lpToTa]->(ta:TrackArtist)<-[:HAS_SOURCE_ARTIST]-(t)
                    OPTIONAL MATCH (lp)-[lpToTw]->(tw:TrackWriter)<-[:HAS_SOURCE_ARTIST]-(t)
                    DELETE lpToT, lpToTa, lpToTw;
                    // LabelParticipant -> GlobalParticipant
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)<-[gpToLp]-(gp:GlobalParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp)
                    YIELD rel AS rel
                    return true;
                    // Delete LabelParticipant -> GlobalParticipant
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)<-[gpToLp]-(gp:GlobalParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    DELETE gpToLp;
                    // LabelParticipant -> Product
                    match (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(lpToP), {participated_as: lpToP.participated_as}, lpToP, p)
                    YIELD rel AS rel
                    return true;
                    // LabelParticipant -> ArtistInfo
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai)
                    YIELD rel AS rel
                    return true;
                    // Delete old Product LP -> ArtistInfo
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    DELETE cf;
                    // LabelParticipant -> ReleaseArtist
                    match (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MATCH (lp)-[lpToRa]-(ra:ReleaseArtist {productId: p.id})
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(lpToRa), null, lpToRa, ra)
                    YIELD rel AS rel
                    return true;
                    // Delete old LP -> Product/ReleaseArtist
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(p:Product)<-[lpToP]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    OPTIONAL MATCH (lp)-[lpToRa]-(ra:ReleaseArtist {productId: p.id})
                    DELETE lpToP, lpToRa;
                    // LabelParticipant -> ArtistInfo
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai)
                    YIELD rel AS rel
                    return true;
                    // Delete old LP -> ArtistInfo
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[lpToP]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    DELETE cf;
                    // LabelParticipant -> Project
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[lpToP]->(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(pr, type(lpToP), null, lpToP, nlp)
                    YIELD rel AS rel
                    return true;
                    // Delete old LP -> Project
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[lpToP]->(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    DELETE lpToP;
                    // LP -> LabelSoundRecordingParticipation
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]->(lsr:LabelSoundRecording)<-[:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation)<-[hlsrp:HAS_LABEL_SOUND_RECORDING_PARTICIPATION]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime()
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt'])
                    MERGE (i:IncrementId {nodeName: 'LabelParticipant'})
                        ON CREATE SET i.id = 1
                        ON MATCH SET i.id = i.id + 1
                    SET nlp.id = COALESCE(nlp.id, i.id)
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(hlsrp), null, hlsrp, lsrp)
                    YIELD rel AS rel
                    return true;
                    // LSR -> GlobalSoundRecording
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)<-[lsrToGsr]-(gsr:GlobalSoundRecording)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlsr.id = apoc.create.uuid(),
                            nlsr.createdAt = datetime()
                        SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt'])
                    WITH *
                    CALL apoc.merge.relationship(gsr, type(lsrToGsr), null, lsrToGsr, nlsr)
                    YIELD rel
                    return true;
                    // Delete LSR -> GlobalSoundRecording
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)<-[lsrToGsr]-(gsr:GlobalSoundRecording)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    return true;
                    // LSR -> Track
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlsr.id = apoc.create.uuid(),
                            nlsr.createdAt = datetime()
                        SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt'])
                    WITH *
                    CALL apoc.merge.relationship(t, type(lsrToT), null, lsrToT, nlsr)
                    YIELD rel
                    return true;
                    MATCH (v:Vendor {id: $vendorId})<-[:BELONGS_TO]-(pr:Project {id: $projectId})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    DELETE lsrToT;
                ",
                {
                    vendorId: pr.vendorId,
                    projectId: pr.id
                }
                ) yield row, result
                return true;
            ]]>
        </query>
    </changeset>
    <changeset id="int1088-neo4j-link-14133-Baga-Biga-artist-profile-spotify-apple-after-d3-conversion:2" author="nlichtenstein" run-on-change="true">
        <query>
             <![CDATA[
                MATCH (lp:LabelParticipant)
                WHERE lp.vendorId in [14133] AND lp.subaccountId <> 0
                MATCH (v:Vendor)
                WHERE v.id = lp.vendorId
                MATCH (sa:Subaccount)
                WHERE sa.id = lp.subaccountId
                MERGE (v)-[:HAS_LABEL_PARTICIPANT]->(lp)
                MERGE (sa)-[:HAS_LABEL_PARTICIPANT]->(lp)
                RETURN true;
            ]]>
        </query>
    </changeset>
</changelog>
