--liquibase formatted cypher --changeset sergio.martin:CCM-2937_create_identity_generate_failure_report MERGE (i:Identity {id: "c754cce4-1d1b-4c5f-a27c-d544ff6abc87"}) ON CREATE SET i.createdAt = datetime(), i.createdBy = "http://jira.theorchard.com/browse/CCM-2937", i.auditUser = "7a5a3822-9753-4f2d-8302-9a2fd71e06ff" SET i.name = "lambda-product-staging-generate-failure-report", i.updatedAt = datetime(), i.updatedBy = "http://jira.theorchard.com/browse/CCM-2937" WITH i OPTIONAL MATCH (i)-[:HAS_PROFILE]->(pExisting:Profile {profileType: "ContentProfile"}) WITH i, pExisting FOREACH (_ IN CASE WHEN pExisting IS NULL THEN [1] ELSE [] END | MERGE (increment:IncrementId {nodeName: "Profile"}) ON CREATE SET increment.id = 2 ON MATCH SET increment.id = increment.id + 1 CREATE (pNew:Profile { uuid: randomUUID(), profileType: "ContentProfile", profileId: increment.id, roles: [], fullCatalogAccess:true, profileName: i.name, createdAt: datetime(), createdBy: "http://jira.theorchard.com/browse/CCM-2937", updatedAt: datetime(), updatedBy: "http://jira.theorchard.com/browse/CCM-2937" }) MERGE (i)-[:HAS_PROFILE]->(pNew) ) WITH i MATCH (i)-[:HAS_PROFILE]->(p:Profile {profileType: "ContentProfile"}) SET p.roles = coalesce(p.roles, []), p.fullCatalogAccess = true, p.profileName = i.name, p.updatedAt = datetime(), p.updatedBy = "http://jira.theorchard.com/browse/CCM-2937" WITH i, p MATCH (v:Vendor {id: "*"}) MERGE (p)-[:HAS_ACCESS_TO]->(v) RETURN i, p, v; --rollback MATCH (i:Identity {id: "c754cce4-1d1b-4c5f-a27c-d544ff6abc87"}) --rollback OPTIONAL MATCH (i)-[:HAS_PROFILE]->(p:Profile {profileType: "ContentProfile"}) --rollback WITH i, p --rollback FOREACH (_ IN CASE WHEN p IS NULL THEN [] ELSE [1] END | DETACH DELETE p) --rollback DETACH DELETE i;