"""Cypher queries for vendor to d3 data alignment.""" # ruff: noqa track_label_participant_to_global_participant = """ CALL apoc.periodic.iterate( " // LabelParticipant -> GlobalParticipant MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(gp:GlobalParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, gpToLp, gp ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/track_label_participant_to_global_participant' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/track_label_participant_to_global_participant' WITH * CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp) YIELD rel AS rel RETURN nlp as labelParticipant; ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ track_label_participant_to_artist_info = """ CALL apoc.periodic.iterate( " // Track LabelParticipant -> ArtistInfo MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, cf, ai ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/track_label_participant_to_artist_info' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/track_label_participant_to_global_participant' WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai) YIELD rel AS rel RETURN nlp as labelParticipant", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_track_label_participant_to_artist_info_relation = """ // Delete old Track LP -> ArtistInfo MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId DELETE cf; """ label_participant_to_track = """ CALL apoc.periodic.iterate( " // LabelParticipant -> Track MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, lpToT, t ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_track' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_track' WITH * CALL apoc.merge.relationship(nlp, type(lpToT), {participated_as: lpToT.participated_as}, lpToT, t) YIELD rel AS rel1 RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ label_participant_to_track_artist = """ CALL apoc.periodic.iterate( " // LabelParticipant -> TrackArtist MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId MATCH (lp)-[cf:CREATED_FROM]->(ta:TrackArtist)<-[:HAS_SOURCE_ARTIST]-(t) RETURN pr, lp, cf, ta ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_track_artist' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_track_artist' WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ta) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ label_participant_track_writer = """ CALL apoc.periodic.iterate( " // LabelParticipant -> TrackWriter MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId MATCH (lp)-[cf:CREATED_FROM]->(tw:TrackWriter)<-[:HAS_SOURCE_ARTIST]-(t) RETURN pr, lp, cf, tw ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_track_writer' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_track_writer' WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, tw) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ create_used_to_participate_in_track_relation = """ // Preserve the originating LP's Track participation as history before it is deleted, // mirroring create_used_to_belong_to_relation so the originating artist keeps access. MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId // Key the merge on participated_as so a multi-role participant yields one // shadow edge per role, matching the PARTITION BY (..., PARTICIPATED_AS) // grain of LABEL_PARTICIPANT_PARTICIPATED_IN_ORCHARD_PRODUCT downstream. // coalesce to '' because participated_as is null on a large share of // PARTICIPATED_IN edges and Cypher cannot MERGE on a null property value (the // value, literal or parameterized, raises an error). '' never occurs as a real // role, so it is an unambiguous "no role" bucket; access ignores the value. MERGE (lp)-[u:USED_TO_PARTICIPATE_IN {participated_as: coalesce(lpToT.participated_as, '')}]->(t) ON CREATE SET // Carry forward the participant's in-track ordering so the shadow edge // is a faithful copy of the PARTICIPATED_IN edge it replaces. Only the // Track edge has sequenceNumber (set by track_set_sequence_numbers); the // Product variant has no such property, so it does not copy it. u.sequenceNumber = lpToT.sequenceNumber, u.createdAt = coalesce(lpToT.createdAt, datetime()), u.createdBy = coalesce(lpToT.createdBy, 'lambda-kinesis-to-neo4j/create_used_to_participate_in_track_relation'), u.lastModifiedAt = datetime(), u.lastModifiedBy = 'lambda-kinesis-to-neo4j/create_used_to_participate_in_track_relation' ON MATCH SET u.lastModifiedAt = datetime(), u.lastModifiedBy = 'lambda-kinesis-to-neo4j/create_used_to_participate_in_track_relation'; """ remove_label_participant_to_track_artist_relation = """ // Delete old LP -> Track/TrackArtist/TrackWriter MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId OPTIONAL MATCH (lp)-[lpToTa:CREATED_FROM]->(:TrackArtist)<-[:HAS_SOURCE_ARTIST]-(t) OPTIONAL MATCH (lp)-[lpToTw:CREATED_FROM]->(:TrackWriter)<-[:HAS_SOURCE_ARTIST]-(t) DELETE lpToT, lpToTa, lpToTw; """ product_label_participant_to_global_participant = """ CALL apoc.periodic.iterate( " // LabelParticipant -> GlobalParticipant MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(gp:GlobalParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, gpToLp, gp ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/product_label_participant_to_global_participant' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/product_label_participant_to_global_participant' WITH * CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ label_participant_product = """ CALL apoc.periodic.iterate( " // LabelParticipant -> Product MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, lpToP, p ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_product' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_product' WITH * CALL apoc.merge.relationship(nlp, type(lpToP), {participated_as: lpToP.participated_as}, lpToP, p) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ label_participant_to_artist_info = """ CALL apoc.periodic.iterate( " // Product LabelParticipant -> ArtistInfo MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, cf, ai ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_artist_info' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_artist_info' WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_label_participant_to_artist_info_relation = """ // Delete old Product LP -> ArtistInfo MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId DELETE cf; """ label_participant_to_release_artist = """ CALL apoc.periodic.iterate( " // LabelParticipant -> ReleaseArtist MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(p:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId MATCH (lp)-[lpToRa:CREATED_FROM]->(ra:ReleaseArtist {productId: p.id}) RETURN pr, lp, lpToRa, ra ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_release_artist' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_release_artist' WITH * CALL apoc.merge.relationship(nlp, type(lpToRa), null, lpToRa, ra) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ create_used_to_participate_in_product_relation = """ // Preserve the originating LP's Product participation as history before it is deleted, // mirroring create_used_to_belong_to_relation so the originating artist keeps access. MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId // Key the merge on participated_as so a multi-role participant yields one // shadow edge per role, matching the PARTITION BY (..., PARTICIPATED_AS) // grain of LABEL_PARTICIPANT_PARTICIPATED_IN_ORCHARD_PRODUCT downstream. // coalesce to '' because participated_as is null on a large share of // PARTICIPATED_IN edges and Cypher cannot MERGE on a null property value (the // value, literal or parameterized, raises an error). '' never occurs as a real // role, so it is an unambiguous "no role" bucket; access ignores the value. MERGE (lp)-[u:USED_TO_PARTICIPATE_IN {participated_as: coalesce(lpToP.participated_as, '')}]->(p) ON CREATE SET u.createdAt = coalesce(lpToP.createdAt, datetime()), u.createdBy = coalesce(lpToP.createdBy, 'lambda-kinesis-to-neo4j/create_used_to_participate_in_product_relation'), u.lastModifiedAt = datetime(), u.lastModifiedBy = 'lambda-kinesis-to-neo4j/create_used_to_participate_in_product_relation' ON MATCH SET u.lastModifiedAt = datetime(), u.lastModifiedBy = 'lambda-kinesis-to-neo4j/create_used_to_participate_in_product_relation'; """ remove_label_participant_to_release_artist_relation = """ // Delete old LP -> Product/ReleaseArtist MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId OPTIONAL MATCH (lp)-[lpToRa:CREATED_FROM]->(:ReleaseArtist {productId: p.id}) DELETE lpToP, lpToRa; """ label_participant_to_project_artist = """ CALL apoc.periodic.iterate( " // LabelParticipant -> ArtistInfo MATCH (pr:Project {id: $project_id})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, cf, ai ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_project_artist' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_project_artist' WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_label_participant_to_project_artist_info_relation = """ // Delete old LP -> ArtistInfo MATCH (pr:Project {id: $project_id})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId DELETE cf; """ label_participant_project = """ CALL apoc.periodic.iterate( " // LabelParticipant -> Project MATCH (pr:Project {id: $project_id})-[lpToP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, lpToP ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_project' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_project' WITH * CALL apoc.merge.relationship(pr, type(lpToP), null, lpToP, nlp) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_label_participant_to_project_relation = """ // Delete old LP -> Project MATCH (pr:Project {id: $project_id})-[lpToP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId DELETE lpToP; """ label_participant_to_label_sound_recording_participation = """ CALL apoc.periodic.iterate( " // LP -> LabelSoundRecordingParticipation MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[:IS_PLACEMENT_OF]->(:LabelSoundRecording)<-[:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation)<-[hlsrp:HAS_LABEL_SOUND_RECORDING_PARTICIPATION]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OR lp.vendorId <> pr.vendorId RETURN pr, lp, hlsrp, lsrp ", " CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlp.id = toInteger(rand() * datetime.realtime().epochMillis), nlp.uuid = randomUUID(), nlp.createdAt = datetime(), nlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_sound_recording_participation' SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlp.lastModifiedAt = datetime(), nlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_sound_recording_participation' WITH * CALL apoc.merge.relationship(nlp, type(hlsrp), null, hlsrp, lsrp) YIELD rel AS rel RETURN nlp as labelParticipant ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_label_participant_to_label_sound_recording_participation_relation = """ // Delete old LP -> LabelSoundRecordingParticipation MATCH (pr:Project {id: $project_id})-[: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 OR lp.vendorId <> pr.vendorId DELETE hlsrp; """ label_sound_recording_to_label_sound_recording_participation = """ CALL apoc.periodic.iterate( " // LSR -> LabelSoundRecordingParticipation MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)<-[olsr:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation) WHERE lsr.subaccountId <> pr.subaccountId OR lsr.vendorId <> pr.vendorId RETURN pr, lsr, olsr, lsrp ", " MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlsr.id = randomUUID(), nlsr.createdAt = datetime(), nlsr.createdBy = 'lambda-kinesis-to-neo4j/label_sound_recording_to_labbel_sound_recording_participation' SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlsr.lastModifiedAt = datetime(), nlsr.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_sound_recording_to_labbel_sound_recording_participation' WITH * CALL apoc.merge.relationship(lsrp, type(olsr), {}, olsr, nlsr) YIELD rel RETURN nlsr as labelSoundRecording ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_label_sound_recording_to_label_sound_recording_participation_relation = """ MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)<-[olsr:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation) WHERE lsr.subaccountId <> pr.subaccountId OR lsr.vendorId <> pr.vendorId DELETE olsr; """ label_participant_global_sound_recording_participation = """ CALL apoc.periodic.iterate( " // LSR -> GlobalSoundRecording MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording)<-[lsrToGsr:REPRESENTS]-(gsr:GlobalSoundRecording) WHERE lsr.subaccountId <> pr.subaccountId OR lsr.vendorId <> pr.vendorId RETURN pr, lsr, lsrToGsr, gsr ", " MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlsr.id = randomUUID(), nlsr.createdAt = datetime(), nlsr.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_sound_recording_participation' SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlsr.lastModifiedAt = datetime(), nlsr.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_global_sound_recording_participation' WITH * CALL apoc.merge.relationship(gsr, type(lsrToGsr), null, lsrToGsr, nlsr) YIELD rel RETURN true ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ label_sound_recording_to_track = """ CALL apoc.periodic.iterate( " // LSR -> Track MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording) WHERE lsr.subaccountId <> pr.subaccountId OR lsr.vendorId <> pr.vendorId RETURN pr, lsr, lsrToT, t ", " MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId}) ON CREATE SET nlsr.id = randomUUID(), nlsr.createdAt = datetime(), nlsr.createdBy = 'lambda-kinesis-to-neo4j/label_sound_recording_to_track' SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']), nlsr.lastModifiedAt = datetime(), nlsr.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_sound_recording_to_track' WITH * CALL apoc.merge.relationship(t, type(lsrToT), null, lsrToT, nlsr) YIELD rel RETURN nlsr as labelSoundRecording ", {batchSize:1, iterateList:true, parallel:false, params: {project_id: $project_id}} ) YIELD total, failedOperations, errorMessages, failedBatches, batch RETURN total, failedOperations, errorMessages, failedBatches, batch; """ remove_track_label_sound_recording_relation = """ MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[lsrToT:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording) WHERE lsr.subaccountId <> pr.subaccountId OR lsr.vendorId <> pr.vendorId DELETE lsrToT; """ remove_label_participant_to_subaccount_relation = """ MATCH (lp:LabelParticipant)<-[sahlp:HAS_LABEL_PARTICIPANT]-(sa:Subaccount) WHERE lp.vendorId = $vendor_id and lp.subaccountId <> sa.id DELETE sahlp; """ create_used_to_belong_to_relation = """ MATCH (project:Project {id: $project_id})-[oldrel:BELONGS_TO]->(oldVendor:Vendor) WHERE oldVendor.vendorId <> project.vendorId MERGE (project)-[utbt:USED_TO_BELONG_TO]->(oldVendor) ON CREATE SET utbt.createdAt = oldrel.createdAt, utbt.createdBy = oldrel.createdBy, utbt.lastModifiedAt = datetime(), utbt.lastModifiedBy = 'lambda-kinesis-to-neo4j/create_used_to_belong_to_relation' ON MATCH SET utbt.lastModifiedAt = datetime(), utbt.lastModifiedBy = 'lambda-kinesis-to-neo4j/create_used_to_belong_to_relation' """ remove_old_vendor_project_relation = """ MATCH (project:Project {id: $project_id})-[oldrel:BELONGS_TO]->(l2:Vendor) where l2.vendorId <> project.vendorId DETACH DELETE oldrel """ label_participant_to_label_relationship = """ MATCH (lp:LabelParticipant) WHERE lp.vendorId = $vendor_id MATCH (v:Vendor) WHERE v.id = lp.vendorId MERGE (v)-[vhlp:HAS_LABEL_PARTICIPANT]->(lp) ON CREATE SET vhlp.createdAt = datetime(), vhlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_relationship', vhlp.lastModifiedAt = datetime(), vhlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_relationship' WITH lp WHERE lp.subaccountId <> 0 MATCH (sa:Subaccount) WHERE sa.id = lp.subaccountId MERGE (sa)-[sahlp:HAS_LABEL_PARTICIPANT]->(lp) ON CREATE SET sahlp.createdAt = datetime(), sahlp.createdBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_relationship', sahlp.lastModifiedAt = datetime(), sahlp.lastModifiedBy = 'lambda-kinesis-to-neo4j/label_participant_to_label_relationship' RETURN true; """ link_label_participant_to_global_participant = """ MATCH (pr:Project {id: $project_id})-[:BELONGS_TO]->(:Vendor)-[:HAS_LABEL_PARTICIPANT]->(lp:LabelParticipant) WHERE lp.spotifyId IS NOT NULL AND NOT EXISTS((:GlobalParticipant { spotifyId: lp.spotifyId })-[:REPRESENTS]->(lp)) MERGE (gp:GlobalParticipant {spotifyId: lp.spotifyId}) ON CREATE SET gp.id = randomUUID(), gp.name = lp.name, gp.appleMusicId = lp.appleMusicId, gp.createdAt = datetime(), gp.createdBy = 'kinesis-to-neo4j/link_label_participant_to_global_participant', gp.lastModifiedAt = datetime(), gp.lastModifiedBy = 'kinesis-to-neo4j/link_label_participant_to_global_participant' MERGE (gp)-[gpToLp:REPRESENTS]->(lp) ON CREATE SET gpToLp.createdAt = datetime(), gpToLp.createdBy = "kinesis-to-neo4j/link_label_participant_to_global_participant" """ MOVE_PROJECT_QUERIES = ( track_label_participant_to_global_participant, track_label_participant_to_artist_info, remove_track_label_participant_to_artist_info_relation, label_participant_to_track, label_participant_to_track_artist, label_participant_track_writer, create_used_to_participate_in_track_relation, remove_label_participant_to_track_artist_relation, product_label_participant_to_global_participant, label_participant_product, label_participant_to_artist_info, remove_label_participant_to_artist_info_relation, label_participant_to_release_artist, create_used_to_participate_in_product_relation, remove_label_participant_to_release_artist_relation, label_participant_to_project_artist, remove_label_participant_to_project_artist_info_relation, label_participant_project, remove_label_participant_to_project_relation, label_participant_to_label_sound_recording_participation, remove_label_participant_to_label_sound_recording_participation_relation, label_sound_recording_to_label_sound_recording_participation, remove_label_sound_recording_to_label_sound_recording_participation_relation, label_participant_global_sound_recording_participation, label_sound_recording_to_track, remove_track_label_sound_recording_relation, remove_label_participant_to_subaccount_relation, label_participant_to_label_relationship, create_used_to_belong_to_relation, remove_old_vendor_project_relation, link_label_participant_to_global_participant, )