From 887a6d201f8140b280a99f01c19b10b0cf92d7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Fri, 18 Jan 2019 23:53:00 +0100 Subject: [PATCH] Import contributions to neo4j --- neo4j/import/contributions.cql | 23 +++++++++++++++++++++++ neo4j/import/{import.todo => todo} | 19 ------------------- neo4j/import/users.cql | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 neo4j/import/contributions.cql rename neo4j/import/{import.todo => todo} (61%) diff --git a/neo4j/import/contributions.cql b/neo4j/import/contributions.cql new file mode 100644 index 000000000..86226b98f --- /dev/null +++ b/neo4j/import/contributions.cql @@ -0,0 +1,23 @@ +CALL apoc.load.json('file:/mongo-export/contributions.json') YIELD value as post +MERGE (p:Post {id: post._id["$oid"]}) +ON CREATE SET +p.title = post.title, +p.slug = post.slug, +p.image = post.teaserImg, +p.content = post.content, +p.contentExcerpt = post.contentExcerpt, +p.visibility = toLower(post.visibility), +p.createdAt = post.createdAt.`$date`, +p.updatedAt = post.updatedAt.`$date`, +p.deleted = post.deleted, +p.disabled = NOT post.isEnabled +WITH p, post, post.tags AS tags, post.categoryIds as categoryIds +UNWIND tags AS tag +UNWIND categoryIds AS categoryId +MATCH (c:Category {id: categoryId}), + (u:User {id: post.userId}) +MERGE (t:Tag {id: apoc.create.uuid(), name: tag}) +MERGE (p)-[:TAGGED]->(t) +MERGE (u)-[:WROTE]->(p) +MERGE (p)-[:CATEGORIZED]->(c) +; diff --git a/neo4j/import/import.todo b/neo4j/import/todo similarity index 61% rename from neo4j/import/import.todo rename to neo4j/import/todo index 672ef0116..2d912c5d4 100644 --- a/neo4j/import/import.todo +++ b/neo4j/import/todo @@ -13,25 +13,6 @@ ON CREATE SET b.key = badge.key, b.status = badge.status -CALL apoc.load.json('file:/mongo-export/contributions.json') YIELD value as post -MERGE (p:Post {id: post._id["$oid"]}) -ON CREATE SET p.title = post.title, - p.slug = post.slug, - p.image = post.teaserImg, - p.content = post.content, - p.contentExcerpt = post.contentExcerpt, - p.visibility = apoc.text.toUpperCase(post.visibility), - p.createdAt = datetime(post.createdAt["$date"]), - p.updatedAt = datetime(post.updatedAt["$date"]) -WITH p, post, post.tags AS tags, post.categoryIds as categoryIds -UNWIND tags AS tag -UNWIND categoryIds AS categoryId -MATCH (c:Category {id: categoryId}), - (u:User {id: post.userId}) -MERGE (t:Tag {id: apoc.create.uuid(), name: tag}) -MERGE (p)-[:TAGGED]->(t) -MERGE (u)-[:WROTE]->(p) -MERGE (p)-[:CATEGORIZED]->(c) CALL apoc.load.json('file:/mongo-export/comments.json') YIELD value as comment diff --git a/neo4j/import/users.cql b/neo4j/import/users.cql index 96abb1637..5f87bb273 100644 --- a/neo4j/import/users.cql +++ b/neo4j/import/users.cql @@ -11,7 +11,7 @@ u.wasInvited = user.wasInvited, u.role = toLower(user.role), u.createdAt = user.createdAt.`$date`, u.updatedAt = user.updatedAt.`$date`, -u.deleted = false, +u.deleted = user.deletedAt IS NOT NULL, u.disabled = false WITH u, user, user.badgeIds AS badgeIds UNWIND badgeIds AS badgeId