mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Import of all users in one script:
```sh docker-compose exec neo4j import/import.sh ```
This commit is contained in:
parent
4534f1ae9e
commit
97e6acf46b
@ -13,6 +13,7 @@ services:
|
|||||||
neo4j:
|
neo4j:
|
||||||
volumes:
|
volumes:
|
||||||
- mongo-export:/mongo-export
|
- mongo-export:/mongo-export
|
||||||
|
- ./neo4j/import:/var/lib/neo4j/import
|
||||||
ports:
|
ports:
|
||||||
- 7687:7687
|
- 7687:7687
|
||||||
- 7474:7474
|
- 7474:7474
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
FROM neo4j:3.5.0
|
FROM neo4j:3.5.0
|
||||||
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.1/apoc-3.5.0.1-all.jar -P plugins/
|
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.1/apoc-3.5.0.1-all.jar -P plugins/
|
||||||
COPY import.cql .
|
COPY import ./import
|
||||||
|
|||||||
4
neo4j/import/import.sh
Executable file
4
neo4j/import/import.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
echo "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;" | cypher-shell
|
||||||
|
cat $SCRIPT_DIRECTORY/*.cql | cypher-shell
|
||||||
@ -13,23 +13,6 @@ ON CREATE SET b.key = badge.key,
|
|||||||
b.status = badge.status
|
b.status = badge.status
|
||||||
|
|
||||||
|
|
||||||
CALL apoc.load.json('file:/mongo-export/users.json') YIELD value as user
|
|
||||||
MERGE(u:User {id: user._id["$oid"]})
|
|
||||||
ON CREATE SET u.name = user.name,
|
|
||||||
u.slug = user.slug,
|
|
||||||
u.email = user.email,
|
|
||||||
u.password = user.password,
|
|
||||||
u.avatar = user.avatar,
|
|
||||||
u.coverImg = user.coverImg,
|
|
||||||
u.wasInvited = user.wasInvited,
|
|
||||||
u.role = apoc.text.toUpperCase(user.role)
|
|
||||||
WITH u, user, user.badgeIds AS badgeIds
|
|
||||||
UNWIND badgeIds AS badgeId
|
|
||||||
MATCH (b:Badge {id: badgeId})
|
|
||||||
MERGE (b)-[:REWARDED]->(u)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CALL apoc.load.json('file:/mongo-export/contributions.json') YIELD value as post
|
CALL apoc.load.json('file:/mongo-export/contributions.json') YIELD value as post
|
||||||
MERGE (p:Post {id: post._id["$oid"]})
|
MERGE (p:Post {id: post._id["$oid"]})
|
||||||
ON CREATE SET p.title = post.title,
|
ON CREATE SET p.title = post.title,
|
||||||
20
neo4j/import/users.cql
Normal file
20
neo4j/import/users.cql
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
CALL apoc.load.json('file:/mongo-export/users.json') YIELD value as user
|
||||||
|
MERGE(u:User {id: user._id["$oid"]})
|
||||||
|
ON CREATE SET
|
||||||
|
u.name = user.name,
|
||||||
|
u.slug = user.slug,
|
||||||
|
u.email = user.email,
|
||||||
|
u.password = user.password,
|
||||||
|
u.avatar = user.avatar,
|
||||||
|
u.coverImg = user.coverImg,
|
||||||
|
u.wasInvited = user.wasInvited,
|
||||||
|
u.role = toLower(user.role),
|
||||||
|
u.createdAt = user.createdAt.`$date`,
|
||||||
|
u.updatedAt = user.updatedAt.`$date`,
|
||||||
|
u.deleted = false,
|
||||||
|
u.disabled = false
|
||||||
|
WITH u, user, user.badgeIds AS badgeIds
|
||||||
|
UNWIND badgeIds AS badgeId
|
||||||
|
MATCH (b:Badge {id: badgeId})
|
||||||
|
MERGE (b)-[:REWARDED]->(u)
|
||||||
|
;
|
||||||
@ -11,7 +11,12 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
const driver = neo4j().getDriver()
|
const driver = neo4j().getDriver()
|
||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
|
|
||||||
query('MATCH (n) DETACH DELETE n', session).then(() => {
|
const deleteAll = `
|
||||||
|
MATCH (n)
|
||||||
|
OPTIONAL MATCH (n)-[r]-()
|
||||||
|
DELETE n,r
|
||||||
|
`
|
||||||
|
query(deleteAll, session).then(() => {
|
||||||
/* eslint-disable-next-line no-console */
|
/* eslint-disable-next-line no-console */
|
||||||
console.log('Successfully deleted all nodes and relations!')
|
console.log('Successfully deleted all nodes and relations!')
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user