Skip to content

Instantly share code, notes, and snippets.

@fbiville
Last active September 3, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbiville/445b8d7b18a82c04b4aff65da04c50ea to your computer and use it in GitHub Desktop.
Save fbiville/445b8d7b18a82c04b4aff65da04c50ea to your computer and use it in GitHub Desktop.
Check a Cypher query against a particular Neo4j version
#!/usr/bin/env bash
set -euo pipefail
function main() {
local query="${1}"
local neo4j_version="${2}"
local password="s3cr3t"
local container_id
echo "### Neo4j ${neo4j_version}"
container_id=$(start_container "${neo4j_version}" "${password}")
trap "stop_container ${container_id}" INT TERM
execute "${container_id}" "${password}" "${query}"
stop_container "${container_id}"
}
function start_container() {
local container_id
local neo4j_version="${1}"
local password="${2}"
container_id=$(docker run --detach --rm \
--env NEO4J_AUTH=neo4j/"${password}" \
--env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
--publish=7687:7687 \
--health-cmd "cypher-shell -u neo4j -p ${password} 'RETURN 1'" \
--health-interval 5s \
--health-timeout 5s \
--health-retries 5 \
neo4j:"${neo4j_version}")
until docker inspect --format "{{json .State.Health.Status }}" "${container_id}" | grep --quiet --max-count 1 "healthy"; do
sleep 5;
done
echo "${container_id}"
}
function execute() {
local container_id="${1}"
local password="${2}"
local query="${3}"
docker exec --interactive --tty "${container_id}" cypher-shell -u neo4j -p "${password}" "${query}" || true
}
function stop_container() {
local container_id="${1}"
docker stop "${container_id}" >/dev/null 2>&1
}
main "${1}" "${2:-latest}"
# INPUT
versions=('3.5' '4.0' '4.1' '4.2' '4.3')
for version in "${versions[@]}"; do
./check-query.sh "CALL db.indexes()" "${version}";
done
# OUTPUT
### Neo4j 3.5
+--------------------------------------------------------------------------------------------------------------+
| description | indexName | tokenNames | properties | state | type | progress | provider | id | failureMessage |
+--------------------------------------------------------------------------------------------------------------+
+--------------------------------------------------------------------------------------------------------------+
0 rows available after 71 ms, consumed after another 2 ms
### Neo4j 4.0
+----------------------------------------------------------------------------------------------------------------+
| id | name | state | populationPercent | uniqueness | type | entityType | labelsOrTypes | properties | provider |
+----------------------------------------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------------------------------------+
0 rows available after 41 ms, consumed after another 9 ms
### Neo4j 4.1
+----------------------------------------------------------------------------------------------------------------+
| id | name | state | populationPercent | uniqueness | type | entityType | labelsOrTypes | properties | provider |
+----------------------------------------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------------------------------------+
0 rows available after 53 ms, consumed after another 11 ms
### Neo4j 4.2
+----------------------------------------------------------------------------------------------------------------+
| id | name | state | populationPercent | uniqueness | type | entityType | labelsOrTypes | properties | provider |
+----------------------------------------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------------------------------------+
0 rows available after 52 ms, consumed after another 6 ms
### Neo4j 4.3
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name | state | populationPercent | uniqueness | type | entityType | labelsOrTypes | properties | provider |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | "index_343aff4e" | "ONLINE" | 100.0 | "NONUNIQUE" | "LOOKUP" | "NODE" | [] | [] | "token-lookup-1.0" |
| 2 | "index_f7700477" | "ONLINE" | 100.0 | "NONUNIQUE" | "LOOKUP" | "RELATIONSHIP" | [] | [] | "token-lookup-1.0" |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows
ready to start consuming query after 53 ms, results consumed after another 8 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment