From a1a8529c9c3a9b4ba277c5e9327497e06cf944fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 19 Jul 2022 15:15:33 +0200 Subject: [PATCH 1/2] Add Neo4j docu for important commands --- neo4j/README.md | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/neo4j/README.md b/neo4j/README.md index a4242b512..c9bff7741 100644 --- a/neo4j/README.md +++ b/neo4j/README.md @@ -7,7 +7,7 @@ database available. The community edition of Neo4J is Free and Open Source and we try our best to keep our application compatible with the community edition only. -## Installation with Docker +## Installation With Docker Run: @@ -19,7 +19,7 @@ You can access Neo4J through [http://localhost:7474/](http://localhost:7474/) for an interactive cypher shell and a visualization of the graph. -## Installation without Docker +## Installation Without Docker Install the community edition of [Neo4j](https://neo4j.com/) along with the plugin [Apoc](https://github.com/neo4j-contrib/neo4j-apoc-procedures) on your system. @@ -51,3 +51,42 @@ in `backend/.env`. Start Neo4J and confirm the database is running at [http://localhost:7474](http://localhost:7474). +## Commands + +Here we describe some rarely used Cypher commands for Neo4j that are needed from time to time: + +### Index And Contraint Commands + +The indexes and constraints of our database are set in `backend/src/db/migrate/store.js`. +This is where the magic happens. + +If they are missing or not set correctly, the browser search will not work or the database seed for development will not work. + +#### Show Indexes And Contraints + +```bash +# in browser command line or cypher shell + +# show all indexes and contraints +$ :schema + +# show all indexes +$ CALL db.indexes(); + +# show all contraints +$ CALL db.constraints(); +``` + +#### Add And Drop Indexes And Contraints + +```bash +# in browser command line or cypher shell + +# create indexes +$ CALL db.index.fulltext.createNodeIndex("post_fulltext_search",["Post"],["title", "content"]); +$ CALL db.index.fulltext.createNodeIndex("user_fulltext_search",["User"],["name", "slug"]); +$ CALL db.index.fulltext.createNodeIndex("tag_fulltext_search",["Tag"],["id"]); + +# drop all indexes and contraints +$ CALL apoc.schema.assert({},{},true) YIELD label, key RETURN * ; +``` From 0487a280a3294e219745c785b6e4f4cbd70038a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 19 Jul 2022 17:46:07 +0200 Subject: [PATCH 2/2] Refine description and add calls of 'prod:migrate init' and single index drop example --- DOCKER_MORE_CLOSELY.md | 4 +++- neo4j/README.md | 45 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/DOCKER_MORE_CLOSELY.md b/DOCKER_MORE_CLOSELY.md index 592b5bb9b..03e6417ec 100644 --- a/DOCKER_MORE_CLOSELY.md +++ b/DOCKER_MORE_CLOSELY.md @@ -22,6 +22,8 @@ For Docker compose `up` or `build` commands, you can use our Apple M1 override f # for development $ docker compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.apple-m1.override.yml up +# only once: init admin user and create indexes and contraints in Neo4j database +$ docker compose exec backend yarn prod:migrate init # clean db $ docker compose exec backend yarn db:reset # seed db @@ -29,7 +31,7 @@ $ docker compose exec backend yarn db:seed # for production $ docker compose -f docker-compose.yml -f docker-compose.apple-m1.override.yml up -# init admin user +# only once: init admin user and create indexes and contraints in Neo4j database $ docker compose exec backend /bin/sh -c "yarn prod:migrate init" ``` diff --git a/neo4j/README.md b/neo4j/README.md index c9bff7741..f2b26d551 100644 --- a/neo4j/README.md +++ b/neo4j/README.md @@ -57,12 +57,48 @@ Here we describe some rarely used Cypher commands for Neo4j that are needed from ### Index And Contraint Commands +If indexes or constraints are missing or not set correctly, the browser search will not work or the database seed for development will not work. + The indexes and constraints of our database are set in `backend/src/db/migrate/store.js`. This is where the magic happens. -If they are missing or not set correctly, the browser search will not work or the database seed for development will not work. +It's called by our `prod:migrate init` command. +This command initializes the Admin user and creates all necessary indexes and constraints in the Neo4j database. -#### Show Indexes And Contraints +***Calls in development*** + +Locally without Docker: + +```bash +# in backend folder +$ yarn prod:migrate init +``` + +Locally with Docker: + +```bash +# in main folder +$ docker compose exec backend yarn prod:migrate init +``` + +***Calls in production*** + +Locally with Docker: + +```bash +# in main folder +$ docker compose exec backend /bin/sh -c "yarn prod:migrate init" +``` + +On a server with Kubernetes cluster: + +```bash +# tested for one backend replica +# !!! be aware of the kubectl context !!! +$ kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "yarn prod:migrate init" +``` + +***Cypher commands to show indexes and contraints*** ```bash # in browser command line or cypher shell @@ -77,7 +113,7 @@ $ CALL db.indexes(); $ CALL db.constraints(); ``` -#### Add And Drop Indexes And Contraints +***Cypher commands to create and drop indexes and contraints*** ```bash # in browser command line or cypher shell @@ -87,6 +123,9 @@ $ CALL db.index.fulltext.createNodeIndex("post_fulltext_search",["Post"],["title $ CALL db.index.fulltext.createNodeIndex("user_fulltext_search",["User"],["name", "slug"]); $ CALL db.index.fulltext.createNodeIndex("tag_fulltext_search",["Tag"],["id"]); +# drop an index +$ DROP CONSTRAINT ON ( image:Image ) ASSERT image.url IS UNIQUE + # drop all indexes and contraints $ CALL apoc.schema.assert({},{},true) YIELD label, key RETURN * ; ```