Ocelot-Social/src/seed/reset-db.js
Robert Schäfer 97e6acf46b Import of all users in one script:
```sh
docker-compose exec neo4j import/import.sh
```
2019-01-18 22:45:29 +01:00

31 lines
751 B
JavaScript

import { query } from '../graphql-schema'
import dotenv from 'dotenv'
import neo4j from '../bootstrap/neo4j'
dotenv.config()
if (process.env.NODE_ENV === 'production') {
throw new Error('YOU CAN`T UNSEED IN PRODUCTION MODE')
}
const driver = neo4j().getDriver()
const session = driver.session()
const deleteAll = `
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r
`
query(deleteAll, session).then(() => {
/* eslint-disable-next-line no-console */
console.log('Successfully deleted all nodes and relations!')
}).catch((err) => {
/* eslint-disable-next-line no-console */
console.log(`Error occurred deleting the nodes and relations (reset the db)\n\n${err}`)
}).finally(() => {
if (session) {
session.close()
}
process.exit(0)
})