"""Queries for Converting Vendor to D3.""" CHECK_PROJECT_SYNC_UP = 'MATCH (v:Vendor)<-[:BELONGS_TO]-(pr) WHERE v.id = {vendor_id} AND pr.subaccountId = 0 return collect(pr.id) AS num' UPDATE_LABELPARTICIPANT_RELATIONSHIPS = """ MATCH (v:Vendor)<-[:BELONGS_TO]-(pr:Project) WHERE v.id = {vendor_id} CALL apoc.cypher.runMany( " // LabelParticipant -> GlobalParticipant MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(gp:GlobalParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp) YIELD rel AS rel return true; // Delete LabelParticipant -> GlobalParticipant MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(:GlobalParticipant) WHERE lp.subaccountId <> pr.subaccountId DELETE gpToLp; // Delete old Product LP -> ArtistInfo MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId DELETE cf; // LabelParticipant -> Track MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(lpToT), {{participated_as: lpToT.participated_as}}, lpToT, t) YIELD rel AS rel1 return true; // LabelParticipant -> TrackArtist MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) 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.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ta) YIELD rel AS rel return true; // LabelParticipant -> TrackWriter MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) 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.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, tw) YIELD rel AS rel return true; // Delete old LP -> Trac/TrackArtist/TrackWriter MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId 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; // LabelParticipant -> GlobalParticipant MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(gp:GlobalParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp) YIELD rel AS rel return true; // Delete LabelParticipant -> GlobalParticipant MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(:GlobalParticipant) WHERE lp.subaccountId <> pr.subaccountId DELETE gpToLp; // LabelParticipant -> Product MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(lpToP), {{participated_as: lpToP.participated_as}}, lpToP, p) YIELD rel AS rel return true; // LabelParticipant -> ArtistInfo MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai) YIELD rel AS rel return true; // Delete old Product LP -> ArtistInfo MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId DELETE cf; // LabelParticipant -> ReleaseArtist MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(p:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MATCH (lp)-[lpToRa:CREATED_FROM]->(ra:ReleaseArtist {{productId: p.id}}) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(lpToRa), null, lpToRa, ra) YIELD rel AS rel return true; // Delete old LP -> Product/ReleaseArtist MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId OPTIONAL MATCH (lp)-[lpToRa:CREATED_FROM]->(:ReleaseArtist {{productId: p.id}}) DELETE lpToP, lpToRa; // LabelParticipant -> ArtistInfo MATCH (pr:Project {{id: $projectId}})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai) YIELD rel AS rel return true; // Delete old LP -> ArtistInfo MATCH (pr:Project {{id: $projectId}})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo) WHERE lp.subaccountId <> pr.subaccountId DELETE cf; // LabelParticipant -> Project MATCH (pr:Project {{id: $projectId}})-[lpToP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(pr, type(lpToP), null, lpToP, nlp) YIELD rel AS rel return true; // Delete old LP -> Project MATCH (pr:Project {{id: $projectId}})-[lpToP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant) WHERE lp.subaccountId <> pr.subaccountId DELETE lpToP; // LP -> LabelSoundRecordingParticipation MATCH (pr:Project {{id: $projectId}})-[: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 CALL apoc.util.sleep(1) MERGE (nlp:LabelParticipant:Orchard {{normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId}}) ON CREATE SET nlp.id = datetime.realtime().epochMillis, nlp.uuid = apoc.create.uuid(), nlp.createdAt = datetime() SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt']) WITH * CALL apoc.merge.relationship(nlp, type(hlsrp), null, hlsrp, lsrp) YIELD rel AS rel return true; // LSR -> GlobalSoundRecording MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording)<-[lsrToGsr:REPRESENTS]-(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 (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording)<-[lsrToGsr:REPRESENTS]-(:GlobalSoundRecording) WHERE lsr.subaccountId <> pr.subaccountId DELETE lsrToGsr; // LSR -> Track MATCH (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT:IS_PLACEMENT_OF]->(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 (pr:Project {{id: $projectId}})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[lsrToT:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording) WHERE lsr.subaccountId <> pr.subaccountId DELETE lsrToT; ", {{ projectId: pr.id }} ) yield row, result return true; """ UPDATE_SUBACCOUNT_RELATIONSHIP = """ MATCH (v:Vendor)-[:HAS_LABEL_PARTICIPANT|CREATED_FROM]-(lp:LabelParticipant) WHERE v.vendorId = {vendor_id} AND lp.subaccountId <> 0 MATCH (sa:Subaccount) WHERE sa.id = lp.subaccountId MERGE (v)-[:HAS_LABEL_PARTICIPANT]->(lp) MERGE (sa)-[:HAS_LABEL_PARTICIPANT]->(lp) RETURN true; """ # Adds CompanyBrand, Vendor, and Subaccount UUID to LabelParticipant UPDATE_LP_REFERENTIAL_UUIDS = """ MATCH (v:Vendor {{vendorId: {vendor_id}}})-[:HAS_LABEL_PARTICIPANT]->(lp:LabelParticipant) OPTIONAL MATCH (v)<-[:HAS_LABEL]-(cb:CompanyBrand)-[:BELONGS_TO]->(pc:ParentCompany) OPTIONAL MATCH (lp)<-[:HAS_LABEL_PARTICIPANT]-(sa:Subaccount) SET lp.companyBrandUUID = cb.uuid, lp.vendorUUID = v.uuid, lp.subaccountUUID = sa.uuid, lp.parentCompanyUUID = pc.uuid RETURN true; """