Setup a routine how to create indices initially

In order to create the indices programmatically we need to change the
default password for security concerns. To create the user we need to
start the neo4j database. So I decided to provide a bash script that
let us do it once the container are started.

In production we must change the NEO4J_PASSWORD.
This commit is contained in:
Robert Schäfer 2019-02-14 16:05:30 +01:00 committed by Matt Rider
parent 832a778ca1
commit 46436ca9b1
9 changed files with 35 additions and 21 deletions

View File

@ -101,7 +101,7 @@ _.env_
```yaml
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=letmein
```

View File

@ -11,6 +11,13 @@ services:
- /nitro-backend/node_modules
command: yarn run dev
neo4j:
environment:
- NEO4J_AUTH=none
ports:
- 7687:7687
- 7474:7474
volumes:
- neo4j-data:/data
volumes:
neo4j-data:

9
docker-compose.prod.yml Normal file
View File

@ -0,0 +1,9 @@
version: "3.7"
services:
neo4j:
environment:
- NEO4J_PASSWORD=letmein
backend:
environment:
- NEO4J_PASSWORD=letmein

View File

@ -27,14 +27,7 @@ services:
context: neo4j
networks:
- hc-network
volumes:
- neo4j-data:/data
environment:
- NEO4J_AUTH=none
networks:
hc-network:
name: hc-network
volumes:
neo4j-data:

View File

@ -1,2 +1,3 @@
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/
COPY migrate.sh /usr/local/bin/migrate

4
neo4j/migrate.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e
echo "CALL dbms.security.changePassword('${NEO4J_PASSWORD}');" | cypher-shell --username neo4j --password neo4j
echo 'CALL db.index.fulltext.createNodeIndex("full_text_search",["Post"],["title", "content"]);' | cypher-shell --username neo4j --password $NEO4J_PASSWORD

View File

@ -1,18 +1,18 @@
import { v1 as neo4j } from 'neo4j-driver'
import dotenv from 'dotenv'
import { v1 as neo4j } from "neo4j-driver";
import dotenv from "dotenv";
dotenv.config()
dotenv.config();
let driver
let driver;
export function getDriver (options = {}) {
export function getDriver(options = {}) {
const {
uri = process.env.NEO4J_URI || 'bolt://localhost:7687',
username = process.env.NEO4J_USERNAME || 'neo4j',
password = process.env.NEO4J_PASSWORD || 'neo4j'
} = options
uri = process.env.NEO4J_URI || "bolt://localhost:7687",
username = process.env.NEO4J_USERNAME || "neo4j",
password = process.env.NEO4J_PASSWORD || "neo4j"
} = options;
if (!driver) {
driver = neo4j.driver(uri, neo4j.auth.basic(username, password))
driver = neo4j.driver(uri, neo4j.auth.basic(username, password));
}
return driver
return driver;
}

View File

@ -34,7 +34,7 @@ export const query = (cypher, session) => {
})
})
}
const queryOne = (cypher, session) => {
export const queryOne = (cypher, session) => {
return new Promise((resolve, reject) => {
query(cypher, session)
.then(res => {

View File

@ -4,7 +4,7 @@ type Query {
findPosts(filter: String!, limit: Int = 10): [Post]! @cypher(
statement: """
CALL db.index.fulltext.queryNodes(
'postTitleAndContent', $filter+'~')
'full_text_search', $filter+'~')
YIELD node AS node
RETURN node
ORDER BY node.createdAt DESC