From 159b85ce7305d886d75f7dd78b94cc5e182505df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 22 Jan 2020 14:36:55 +0100 Subject: [PATCH] Write script for database manipulation that adds new missing notifications --- ...notification_from_report_to_filing_user.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 neo4j/db_manipulation/add_notification_from_report_to_filing_user.sh diff --git a/neo4j/db_manipulation/add_notification_from_report_to_filing_user.sh b/neo4j/db_manipulation/add_notification_from_report_to_filing_user.sh new file mode 100644 index 000000000..15af5c245 --- /dev/null +++ b/neo4j/db_manipulation/add_notification_from_report_to_filing_user.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +ENV_FILE=$(dirname "$0")/.env +[[ -f "$ENV_FILE" ]] && source "$ENV_FILE" + +if [ -z "$NEO4J_USERNAME" ] || [ -z "$NEO4J_PASSWORD" ]; then + echo "Please set NEO4J_USERNAME and NEO4J_PASSWORD environment variables." + echo "Database manipulation is not possible without connecting to the database." + echo "E.g. you could \`cp .env.template .env\` unless you run the script in a docker container" +fi + +until echo 'RETURN "Connection successful" as info;' | cypher-shell +do + echo "Connecting to neo4j failed, trying again..." + sleep 1 +done + +echo " + :begin + MATCH (submitter:User)-[filed:FILED]->(report:Report) + WHERE NOT (submitter)<-[:NOTIFIED]-(report) + CREATE (submitter)<-[notification:NOTIFIED]-(report) + SET notification.createdAt = filed.createdAt, + notification.updatedAt = notification.createdAt, + notification.read = FALSE, + notification.reason = 'filed_report_on_resource'; + :commit +" | cypher-shell \ No newline at end of file