mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Add yarn db:reset script
This commit is contained in:
parent
f78178c545
commit
b5ce0351c7
10
README.md
10
README.md
@ -99,7 +99,7 @@ you build a frontend application without running a neo4j instance.
|
||||
|
||||
Just set `MOCK=true` inside `.env` or pass it on application start.
|
||||
|
||||
## Seeding The Database
|
||||
## Seeding and Unseeding The Database
|
||||
|
||||
Optionally you can seed the GraphQL service by executing mutations that
|
||||
will write sample data to the database:
|
||||
@ -110,6 +110,14 @@ yarn db:seed
|
||||
npm run db:seed
|
||||
```
|
||||
|
||||
For a reset you can use the reset script:
|
||||
|
||||
```bash
|
||||
yarn db:reset
|
||||
# -or-
|
||||
npm run db:reset
|
||||
```
|
||||
|
||||
## Todo`s
|
||||
|
||||
- [x] add jwt authentication
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 0",
|
||||
"start": "./node_modules/.bin/nodemon --exec babel-node src/index.js",
|
||||
"start:debug": "./node_modules/.bin/nodemon --exec babel-node --inspect=0.0.0.0:9229 src/index.js",
|
||||
"db:seed": "concurrently --kill-others --success first 'cross-env GRAPHQL_URI=http://localhost:4001 PERMISSIONS=disabled GRAPHQL_PORT=4001 yarn run start' 'wait-on tcp:4001 && cross-env GRAPHQL_URI=http://localhost:4001 ./node_modules/.bin/babel-node src/seed/seed-db.js'"
|
||||
"db:seed": "concurrently --kill-others --success first 'cross-env GRAPHQL_URI=http://localhost:4001 PERMISSIONS=disabled GRAPHQL_PORT=4001 yarn run start' 'wait-on tcp:4001 && cross-env GRAPHQL_URI=http://localhost:4001 ./node_modules/.bin/babel-node src/seed/seed-db.js'",
|
||||
"db:reset": "concurrently --kill-others --success first 'cross-env GRAPHQL_URI=http://localhost:4001 PERMISSIONS=disabled GRAPHQL_PORT=4001 yarn run start' 'wait-on tcp:4001 && cross-env GRAPHQL_URI=http://localhost:4001 ./node_modules/.bin/babel-node src/seed/unseed-db.js'"
|
||||
},
|
||||
"author": "Human Connection gGmbH",
|
||||
"license": "MIT",
|
||||
|
||||
@ -10,7 +10,7 @@ export const typeDefs =
|
||||
fs.readFileSync(process.env.GRAPHQL_SCHEMA || path.join(__dirname, "schema.graphql"))
|
||||
.toString('utf-8')
|
||||
|
||||
const query = (cypher, session) => {
|
||||
export const query = (cypher, session) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = []
|
||||
session
|
||||
|
||||
23
src/seed/unseed-db.js
Normal file
23
src/seed/unseed-db.js
Normal file
@ -0,0 +1,23 @@
|
||||
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()
|
||||
|
||||
query('MATCH (n) DETACH DELETE n', session).then(() => {
|
||||
console.log('Successfully deleted all nodes and relations!')
|
||||
}).catch((err) => {
|
||||
console.log(`Error occurred deleting the nodes and relations (reset the db)\n\n${err}`)
|
||||
}).finally(() => {
|
||||
if (session) {
|
||||
session.close()
|
||||
}
|
||||
process.exit(0)
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user