Skip to content

Commit 650e8ee

Browse files
committed
Add a script to export the whole database as CSV
1 parent 5bb061d commit 650e8ee

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

.github/workflows/code-reports.yml

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

121+
- name: Export database
122+
working-directory: temp
123+
run: ./../scripts/ExportDatabaseAsCSV.sh
124+
env:
125+
NEO4J_INITIAL_PASSWORD: ${{ secrets.NEO4J_INITIAL_PASSWORD }}
126+
127+
# Upload Database Export
128+
- name: Archive exported database
129+
uses: actions/upload-artifact@v3
130+
with:
131+
name: code-report-database-export-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
132+
path: ./temp/**/import/
133+
if-no-files-found: error
134+
retention-days: 5
135+
121136
# Commit and push the native image agent results
122137
- name: Display environment variable "github.event_name"
123138
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/ExportDatabaseAsCSV.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
14+
echo "ExportDatabase: SCRIPTS_DIR=${SCRIPTS_DIR}"
15+
16+
# Get the "cypher" directory by taking the path of this script and going two directory up and then to "cypher".
17+
CYPHER_DIR=${CYPHER_DIR:-"${SCRIPTS_DIR}/../cypher"}
18+
echo "ExportDatabase: CYPHER_DIR=$CYPHER_DIR"
19+
20+
# Define functions to execute a cypher query from within the given file (first and only argument)
21+
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
22+
23+
# Execute Procedure
24+
execute_cypher_summarized "${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)