Skip to content

Commit b023888

Browse files
authored
Merge pull request #5 from JohT/feature/database-export
Add a script to export the whole database as CSV
2 parents fa82eb4 + df34131 commit b023888

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

.github/workflows/code-reports.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ jobs:
118118
if-no-files-found: error
119119
retention-days: 5
120120

121+
# Upload Database Export
122+
- name: Archive exported database
123+
uses: actions/upload-artifact@v3
124+
with:
125+
name: code-report-database-export-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
126+
path: ./temp/**/import
127+
if-no-files-found: error
128+
retention-days: 5
129+
121130
# Commit and push the native image agent results
122131
- name: Display environment variable "github.event_name"
123132
run: echo "github.event_name=${{ github.event_name }}"

cypher/CYPHER.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Script | Directory | Description
7171
| [Cyclic_Dependencies_Concatenated.cypher](./Cyclic_Dependencies/Cyclic_Dependencies_Concatenated.cypher) | Cyclic_Dependencies | Cyclic Dependencies Concatenated |
7272
| [Cyclic_Dependencies_as_List.cypher](./Cyclic_Dependencies/Cyclic_Dependencies_as_List.cypher) | Cyclic_Dependencies | Cyclic Dependencies as List |
7373
| [Cyclic_Dependencies_as_unwinded_List.cypher](./Cyclic_Dependencies/Cyclic_Dependencies_as_unwinded_List.cypher) | Cyclic_Dependencies | Cyclic Dependencies as unwinded List |
74+
| [Export_the_whole_database_as_CSV.cypher](./Export_the_whole_database_as_CSV.cypher) | | Export the whole database as CSV |
7475
| [External_package_usage_overall.cypher](./External_Dependencies/External_package_usage_overall.cypher) | External_Dependencies | External package usage overall |
7576
| [External_package_usage_per_artifact.cypher](./External_Dependencies/External_package_usage_per_artifact.cypher) | External_Dependencies | External package usage per artifact |
7677
| [External_package_usage_per_artifact_and_package.cypher](./External_Dependencies/External_package_usage_per_artifact_and_package.cypher) | External_Dependencies | External package usage per artifact and package |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Export the whole database as CSV
2+
CALL apoc.export.csv.all("codegraph.csv", {})

scripts/reports/DatabaseCsvExport.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# Exports the whole graph database as a CSV file using the APOC procedure "apoc.export.csv.all"
4+
# The exported file can be found in the subdirectory "import" inside the tools/neo4j.. directory.
5+
6+
# Overrideable Constants (defaults also defined in sub scripts)
7+
REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"}
8+
9+
## Get this "scripts/reports" directory if not already set
10+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
11+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
12+
# This way non-standard tools like readlink aren't needed.
13+
REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
14+
echo "ExternalDependenciesCsv: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
15+
16+
# Get the "scripts" directory by taking the path of this script and going one directory up.
17+
SCRIPTS_DIR=${SCRIPTS_DIR:-"${REPORTS_SCRIPT_DIR}/.."}
18+
echo "ExternalDependenciesCsv SCRIPTS_DIR=${SCRIPTS_DIR}"
19+
20+
# Get the "cypher" directory by taking the path of this script and going two directory up and then to "cypher".
21+
CYPHER_DIR=${CYPHER_DIR:-"${SCRIPTS_DIR}/../cypher"}
22+
echo "ExportDatabase: CYPHER_DIR=$CYPHER_DIR"
23+
24+
# Define functions to execute a cypher query from within the given file (first and only argument)
25+
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
26+
27+
# Execute Database Export Procedure in background
28+
# The exported file can then be found in the subdirectory "import" inside the tools/neo4j.. directory.
29+
execute_cypher "${CYPHER_DIR}/Export_the_whole_database_as_CSV.cypher" &

scripts/setupNeo4j.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ NEO4J_BOLT_PORT=${NEO4J_BOLT_PORT:-"7687"}
2121
NEO4J_INSTALLATION_NAME="neo4j-${NEO4J_EDITION}-${NEO4J_VERSION}"
2222
NEO4J_INSTALLATION_DIRECTORY="${TOOLS_DIRECTORY}/${NEO4J_INSTALLATION_NAME}"
2323
NEO4J_CONFIG="${NEO4J_INSTALLATION_DIRECTORY}/conf/neo4j.conf"
24+
NEO4J_APOC_CONFIG="${NEO4J_INSTALLATION_DIRECTORY}/conf/apoc.conf"
2425
NEO4J_APOC_PLUGIN_ARTIFACT="apoc-${NEO4J_APOC_PLUGIN_VERSION}-all.jar"
2526
NEO4J_GDS_PLUGIN_ARTIFACT="neo4j-graph-data-science-${NEO4J_GDS_PLUGIN_VERSION}.jar"
2627

@@ -147,6 +148,15 @@ if [ ! -f "${NEO4J_INSTALLATION_DIRECTORY}/plugins/${NEO4J_APOC_PLUGIN_ARTIFACT}
147148
echo "setupNeo4j: Failed to download and install ${NEO4J_APOC_PLUGIN_ARTIFACT}"
148149
exit 1
149150
fi
151+
152+
# Configure Neo4j Plugin "Awesome Procedures for Neo4j" (APOC)
153+
echo "setupNeo4j: Configuring Neo4j Plugin ${NEO4J_APOC_PLUGIN_ARTIFACT} (APOC)"
154+
{
155+
echo "# Reference: https://neo4j.com/docs/apoc/current/config/#_apoc_export_file_enabled"
156+
echo ""
157+
echo "# Enables writing local files to disk for file export. Default=false"
158+
echo "apoc.export.file.enabled=true"
159+
} >> "${NEO4J_APOC_CONFIG}"
150160
else
151161
echo "setupNeo4j: ${NEO4J_APOC_PLUGIN_ARTIFACT} already installed"
152162
fi

0 commit comments

Comments
 (0)