--liquibase formatted cypher --changeset kturner:NR-3167-update-rubyworks-collection-date:1 runOnChange: true UNWIND [ "GBMGR0700042", "GBMGR0700043", "GBMGR0700044", "GBMGR0700045", "GBMGR0700046", "GBMGR0700047", "GBMGR0700048", "GBMGR0700049", "GBMGR0700050", "GBMGR0700051", "GBMGR0700052", "GBMGR0700053", "IEACJ2200022" ] as isrc MATCH (sr: NrSoundRecording:NrOwnership)-[rel:HAS_OWNERSHIP_RULE_MONETIZE]->(s:NrOwnershipService) WHERE sr.isrc=isrc and rel.vendorId = 68726 and s.territory="WORLD" WITH sr, rel as oldRel OPTIONAL MATCH (sr)-[oldCarveoutRel:HAS_OWNERSHIP_RULE_CARVEOUT {vendorId: 68726}]->(se2:NrOwnershipService) WITH collect(distinct(se2.territory)) as carveouts, sr, oldRel MATCH (service:NrOwnershipService) WHERE service.territory <> "WORLD" AND NOT service.territory IN carveouts MERGE (sr)-[newRel:HAS_OWNERSHIP_RULE_MONETIZE {vendorId: oldRel.vendorId}]->(service) ON CREATE SET newRel.percentage = oldRel.percentage, newRel.endDate = oldRel.endDate, newRel.startDate = CASE WHEN service.territory = "GB" THEN date("2025-03-07") ELSE oldRel.startDate END, newRel.externalId = oldRel.externalId, newRel.subaccountId = oldRel.subaccountId, newRel.id = randomUUID(), newRel.createdBy = 'database/NR-3167-update-rubyworks-collection-date', newRel.createdAt = datetime(), newRel.lastModifiedBy = 'database/NR-3167-update-rubyworks-collection-date', newRel.lastModifiedAt = datetime() ON MATCH SET newRel.percentage = oldRel.percentage, newRel.endDate = oldRel.endDate, newRel.startDate = CASE WHEN service.territory = "GB" THEN date("2025-03-07") ELSE oldRel.startDate END, newRel.externalId = oldRel.externalId, newRel.subaccountId = oldRel.subaccountId, newRel.lastModifiedBy = 'database/NR-3167-update-rubyworks-collection-date', newRel.lastModifiedAt = datetime() WITH sr OPTIONAL MATCH (sr)-[oldWorldRel:HAS_OWNERSHIP_RULE_MONETIZE {vendorId: 68726}]->(worldService:NrOwnershipService) WHERE worldService.territory = "WORLD" DELETE oldWorldRel;