2023-08-15 14:47:29 +00:00

623 lines
21 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Neo4J · Ocelot.Social Developer Documentation</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<meta name="author" content="busFaktor() e.V.">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-hints/plugin-hints.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-tabs2/tabs.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../backend/" />
<link rel="prev" href="../edit-this-documentation.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../edit-this-documentation.html">
<a href="../edit-this-documentation.html">
Edit this Documentation
</a>
</li>
<li class="chapter active" data-level="1.3" data-path="./">
<a href="./">
Neo4J
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../backend/">
<a href="../backend/">
Backend
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="../backend/graphql.html">
<a href="../backend/graphql.html">
GraphQL
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="../backend/neo4j-graphql-js.html">
<a href="../backend/neo4j-graphql-js.html">
neo4j-graphql-js
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="../webapp/">
<a href="../webapp/">
Webapp
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../webapp/components.html">
<a href="../webapp/components.html">
Components
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../webapp/html.html">
<a href="../webapp/html.html">
HTML
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../webapp/scss.html">
<a href="../webapp/scss.html">
SCSS
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="../webapp/vue.html">
<a href="../webapp/vue.html">
Vue
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="../testing.html">
<a href="../testing.html">
Testing Guide
</a>
<ul class="articles">
<li class="chapter " data-level="1.6.1" data-path="../cypress/">
<a href="../cypress/">
End-to-end tests
</a>
</li>
<li class="chapter " data-level="1.6.2" data-path="../webapp/testing.html">
<a href="../webapp/testing.html">
Frontend tests
</a>
</li>
<li class="chapter " data-level="1.6.3" data-path="../backend/testing.html">
<a href="../backend/testing.html">
Backend tests
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.7" data-path="../DOCKER_MORE_CLOSELY.html">
<a href="../DOCKER_MORE_CLOSELY.html">
Docker More Closely
</a>
</li>
<li class="chapter " data-level="1.8" >
<a target="_blank" href="https://github.com/Ocelot-Social-Community/Ocelot-Social-Deploy-Rebranding/blob/master/deployment/README.md">
Deployment
</a>
</li>
<li class="chapter " data-level="1.9" data-path="../CONTRIBUTING.html">
<a href="../CONTRIBUTING.html">
Contributing
</a>
</li>
<li class="chapter " data-level="1.10" data-path="../cypress/features.html">
<a href="../cypress/features.html">
Feature Specification
</a>
</li>
<li class="chapter " data-level="1.11" data-path="../CODE_OF_CONDUCT.html">
<a href="../CODE_OF_CONDUCT.html">
Code of conduct
</a>
</li>
<li class="chapter " data-level="1.12" data-path="../LICENSE.html">
<a href="../LICENSE.html">
License
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >Neo4J</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="neo4j">Neo4J</h1>
<p>Human Connection is a social network. Using a graph based database which can
model nodes and edges natively - a network - feels like an obvious choice. We
decided to use <a href="https://neo4j.com/" target="_blank">Neo4j</a>, the currently most used graph
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.</p>
<h2 id="installation-with-docker">Installation With Docker</h2>
<p>Run:</p>
<pre><code class="lang-bash">docker-compose up
</code></pre>
<p>You can access Neo4J through <a href="http://localhost:7474/" target="_blank">http://localhost:7474/</a>
for an interactive cypher shell and a visualization of the graph.</p>
<h2 id="installation-without-docker">Installation Without Docker</h2>
<p>Install the community edition of <a href="https://neo4j.com/" target="_blank">Neo4j</a> along with the plugin
<a href="https://github.com/neo4j-contrib/neo4j-apoc-procedures" target="_blank">Apoc</a> on your system.</p>
<p>To do so, go to <a href="https://neo4j.com/download-center/#releases" target="_blank">releases</a>, choose
&quot;Community Server&quot;, download the installation files for you operation system
and unpack the files.</p>
<p>Download <a href="https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases" target="_blank">Neo4j Apoc</a>
and drop the <code>.jar</code> file into the <code>plugins</code> folder of the just extracted Neo4j-Server.</p>
<p>Then make sure to allow Apoc procedures by adding the following line to your Neo4j configuration (<code>conf/neo4j.conf</code>):</p>
<pre><code>dbms.security.procedures.unrestricted=apoc.*
</code></pre><h3 id="alternatives">Alternatives</h3>
<p>You can download <a href="https://neo4j.com/download/" target="_blank">Neo4j Desktop</a> and run locally
for development, spin up a
<a href="https://neo4j.com/download/" target="_blank">hosted Neo4j Sandbox instance</a>, run Neo4j in one
of the <a href="https://neo4j.com/developer/guide-cloud-deployment/" target="_blank">many cloud options</a>,
<a href="https://neo4j.com/developer/docker/" target="_blank">spin up Neo4j in a Docker container</a>,
on Arch linux you can install <a href="https://aur.archlinux.org/packages/neo4j-community/" target="_blank">neo4j-community from AUR</a>
or on Debian-based systems install <a href="http://debian.neo4j.org/" target="_blank">Neo4j from the Debian Repository</a>.
Just be sure to update the Neo4j connection string and credentials accordingly
in <code>backend/.env</code>.</p>
<p>Start Neo4J and confirm the database is running at <a href="http://localhost:7474" target="_blank">http://localhost:7474</a>.</p>
<h2 id="commands">Commands</h2>
<p>Here we describe some rarely used Cypher commands for Neo4j that are needed from time to time:</p>
<h3 id="index-and-constraint-commands">Index And Constraint Commands</h3>
<p>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.</p>
<p>The indexes and constraints of our database are set in <code>backend/src/db/migrate/store.js</code>.
This is where the magic happens.</p>
<p>It&apos;s called by our <code>prod:migrate init</code> command.
This command initializes the Admin user and creates all necessary indexes and constraints in the Neo4j database.</p>
<p><strong><em>Calls in development</em></strong></p>
<p>Locally without Docker:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># in backend folder</span>
$ yarn prod:migrate init
</code></pre>
<p>Locally with Docker:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># in main folder</span>
$ docker compose <span class="hljs-built_in">exec</span> backend yarn prod:migrate init
</code></pre>
<p><strong><em>Calls in production</em></strong></p>
<p>Locally with Docker:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># in main folder</span>
$ docker compose <span class="hljs-built_in">exec</span> backend /bin/sh -c <span class="hljs-string">&quot;yarn prod:migrate init&quot;</span>
</code></pre>
<p>On a server with Kubernetes cluster:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># tested for one backend replica</span>
<span class="hljs-comment"># !!! be aware of the kubectl context !!!</span>
$ kubectl -n default <span class="hljs-built_in">exec</span> -it $(kubectl -n default get pods | grep ocelot-backend | awk <span class="hljs-string">&apos;{ print $1 }&apos;</span>) -- /bin/sh -c <span class="hljs-string">&quot;yarn prod:migrate init&quot;</span>
</code></pre>
<p><strong><em>Cypher commands to show indexes and constraints</em></strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># in browser command line or cypher shell</span>
<span class="hljs-comment"># show all indexes and constraints</span>
$ :schema
<span class="hljs-comment"># show all indexes</span>
$ CALL db.indexes();
<span class="hljs-comment"># show all constraints</span>
$ CALL db.constraints();
</code></pre>
<p><strong><em>Cypher commands to create and drop indexes and constraints</em></strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># in browser command line or cypher shell</span>
<span class="hljs-comment"># create indexes</span>
$ CALL db.index.fulltext.createNodeIndex(<span class="hljs-string">&quot;post_fulltext_search&quot;</span>,[<span class="hljs-string">&quot;Post&quot;</span>],[<span class="hljs-string">&quot;title&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>]);
$ CALL db.index.fulltext.createNodeIndex(<span class="hljs-string">&quot;user_fulltext_search&quot;</span>,[<span class="hljs-string">&quot;User&quot;</span>],[<span class="hljs-string">&quot;name&quot;</span>, <span class="hljs-string">&quot;slug&quot;</span>]);
$ CALL db.index.fulltext.createNodeIndex(<span class="hljs-string">&quot;tag_fulltext_search&quot;</span>,[<span class="hljs-string">&quot;Tag&quot;</span>],[<span class="hljs-string">&quot;id&quot;</span>]);
<span class="hljs-comment"># drop an index</span>
$ DROP CONSTRAINT ON ( image:Image ) ASSERT image.url IS UNIQUE
<span class="hljs-comment"># drop all indexes and constraints</span>
$ CALL apoc.schema.assert({},{},<span class="hljs-literal">true</span>) YIELD label, key RETURN * ;
</code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../edit-this-documentation.html" class="navigation navigation-prev " aria-label="Previous page: Edit this Documentation">
<i class="fa fa-angle-left"></i>
</a>
<a href="../backend/" class="navigation navigation-next " aria-label="Next page: Backend">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Neo4J","level":"1.3","depth":1,"next":{"title":"Backend","level":"1.4","depth":1,"path":"backend/README.md","ref":"backend/README.md","articles":[{"title":"GraphQL","level":"1.4.1","depth":2,"path":"backend/graphql.md","ref":"backend/graphql.md","articles":[]},{"title":"neo4j-graphql-js","level":"1.4.2","depth":2,"path":"backend/neo4j-graphql-js.md","ref":"backend/neo4j-graphql-js.md","articles":[]}]},"previous":{"title":"Edit this Documentation","level":"1.2","depth":1,"path":"edit-this-documentation.md","ref":"edit-this-documentation.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","hints","tabs2","theme-simple@git+https://github.com/plugins-zander/gitbook-plugin-theme-simple.git","search-pro@git+https://github.com/plugins-zander/gitbook-plugin-search-pro.git","splitter@git+https://github.com/plugins-zander/gitbook-plugin-splitter.git","edit-link@git+https://github.com/plugins-zander/gitbook-plugin-edit-link.git","gtag@git+https://github.com/plugins-zander/gitbook-plugin-gtag.git","chapter-fold@git+https://github.com/plugins-zander/gitbook-plugin-chapter-fold.git","copy-code-button@git+https://github.com/plugins-zander/gitbook-plugin-copy-code-button.git"],"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"},"pluginsConfig":{"chapter-fold":{},"splitter":{},"search-pro":{},"hints":{"danger":"fa fa-exclamation-circle","info":"fa fa-info-circle","tip":"fa fa-mortar-board","working":"fa fa-wrench"},"sitemap-general":{"prefix":"https://zlogs.net/gitbook-action/"},"fontsettings":{"theme":"white","family":"sans","size":2},"gtag":{"token":""},"tabs2":{},"highlight":{},"theme-simple":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"copy-code-button":{},"edit-link":{"label":"EDIT","base":"https://github.com/Ocelot-Social-Community/Ocelot-Social/edit/master/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"busFaktor() e.V.","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Ocelot.Social Developer Documentation","gitbook":"3.2.3","description":"Developer Documentation by Gitbook-Action"},"file":{"path":"neo4j/README.md","mtime":"2023-03-08T08:34:35.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-08-15T14:47:24.081Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="../gitbook/gitbook-plugin-tabs2/tabs.js"></script>
<script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
<script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
<script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
<script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-gtag/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
<script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>