I'm looking to import data from three different csv's with headers and create relationships between certain nodes. The CSV data looks like this:
activities.csv
activity activityID stakeholder process lifecycle
submit budget aei89302.13 budget analyst AHA application
review budget aei89301.14 program officer AHA application
problems.csv
problem activity activityID
lengthy wait time submit budget aei89302.13
manual data entry submit budget aei89302.13
no clear rules review budget aei89302.14
systems.csv
system activity activityID
email submit budget aei89302.13
excel review budget aei89302.14
Here's my code so far:
CREATE CONSTRAINT ON(a:Activity) ASSERT a.activity_id IS UNIQUE;
CREATE CONSTRAINT ON(s:Stakeholder) ASSERT s.name IS UNIQUE;
CREATE CONSTRAINT ON(p:Process) ASSERT p.name IS UNIQUE;
CREATE CONSTRAINT ON(pr:Problem) ASSERT pr.activity_ID IS UNIQUE;
CREATE CONSTRAINT ON(sy:System) ASSERT sy.activity_ID IS UNIQUE;
LOAD CSV WITH HEADERS FROM "file:///activities.csv" as line
WITH line
MERGE (a:Activity {name:line.activity, id:line.activity_id, lifecycle:line.lifecycle, activity_type:line.activity_type})
MERGE (s:Stakeholder {name :line.stakeholder})
MERGE (p:Process {name: line.process})
CREATE (s)-[:responsible_for]->(a)-[:belongs_to]->(p);
LOAD CSV WITH HEADERS FROM "file:///problems.csv" as line2
WITH line2
CREATE (pr:Problem {name: line2.problem, activity_id:line2.activity_id});
MATCH (pr:Problem), (a:Activity)
WHERE pr.id = a.id
MERGE (a)-[:has_problem] -> (pr);
LOAD CSV WITH HEADERS FROM "file///systems.csv" as line3
WITH line3
CREATE (sy:System {name:line3.system, id:line3.activity_id})
MATCH (a:Activity), (sy:System)
WHERE a.id = sy.id
MERGE (a)-[:has_system] -> (sy);
When I run this, cypher has no problem with the constraint statements or the first load_csv statement, but when it comes to the second load csv (for Problems), I get the following error:
Neo.ClientError.Schema.ConstraintValidationFailed: Node(17781) already exists with label Problem
and property activity_id
= '50ec26ddc31.17'
I have a feeling that the issue is with how I'm writing the constraints, but I'm not 100% sure.