From bcd60c364de10416ee89239cd906742f1fefcdc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 14 Nov 2019 12:15:07 +0100 Subject: [PATCH] Refactor script for db change --- ...ed_relationship_to_decided_relationship.sh | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/neo4j/change_disabled_relationship_to_decided_relationship.sh b/neo4j/change_disabled_relationship_to_decided_relationship.sh index 5e119d84d..2aef78d1a 100755 --- a/neo4j/change_disabled_relationship_to_decided_relationship.sh +++ b/neo4j/change_disabled_relationship_to_decided_relationship.sh @@ -16,12 +16,43 @@ do done echo " -MATCH (moderator:User)-[disabled:DISABLED]->(resource) +// convert old DISABLED to new REVIEWED-Case-FLAGGED structure +MATCH (moderator:User)-[disabled:DISABLED]->(disabledResource) +WHERE disabledResource:User OR disabledResource:Comment OR disabledResource:Post DELETE disabled -CREATE (moderator)-[decision:DECIDED]->(resource) -SET decision.updatedAt = toString(datetime()), decision.createdAt = decision.updatedAt, decision.disable = true, decision.latest = true, decision.closed = false -WITH decision -MATCH (:User)-[report:REPORTED]->(resource) -SET report.closed = false -RETURN decision, report; +CREATE (moderator)-[review:REVIEWED]->(case:Case)-[:FLAGGED]->(disabledResource) +SET review.updatedAt = toString(datetime()), review.createdAt = review.updatedAt, review.disable = true +SET case.id = randomUUID(), case.updatedAt = toString(datetime()), case.createdAt = case.updatedAt, case.disable = true, case.closed = false + +// if disabledResource has no report, then create a moderators default report +WITH moderator, disabledResource, case +//, review +//OPTIONAL MATCH (noReporterDisabledResource:User)-[:REPORTED]->(disabledResource) +//WHERE noReporterDisabledResource IS NULL +OPTIONAL MATCH (:User)-[notExistingReport:REPORTED]->(disabledResource) +WHERE notExistingReport IS NULL +//MATCH (noReporterDisabledResource:User) +//WHERE NOT (noReporterDisabledResource:User)-[:REPORTED]->(disabledResource) +CREATE (moderator)-[addModeratorReport:REPORTED]->(case) +SET addModeratorReport.createdAt = toString(datetime()), addModeratorReport.reasonCategory = 'other', addModeratorReport.reasonDescription = 'Old DISABLED relation had no now mandatory report !!! Created automatically to ensure database consistency! Creation date is when the database manipulation happened.' + +// if disabledResource has reports, then convert them +WITH disabledResource, case +//, review +MATCH (reporterDisabledResource:User)-[existingReport:REPORTED]->(disabledResource) +DELETE existingReport +CREATE (reporterDisabledResource)-[reportDisabledResource:REPORTED]->(case) +SET reportDisabledResource = existingReport + +// for REPORTED resources without DISABLED relation which are handled above, create new REPORTED-Case-FLAGGED structure +WITH +MATCH (reporter:User)-[oldReport:REPORTED]->(noDisabledResource) +WHERE noDisabledResource:User OR noDisabledResource:Comment OR noDisabledResource:Post +DELETE oldReport +CREATE (reporter)-[report:REPORTED]->(case:Case) +MERGE (case)-[:FLAGGED]->(noDisabledResource) +SET report = oldReport +SET case.id = randomUUID(), case.updatedAt = toString(datetime()), case.createdAt = case.updatedAt, case.disable = false, case.closed = false + +RETURN disabledResource, noDisabledResource, review, report, addModeratorReport; " | cypher-shell