Get db manipulation script running

This commit is contained in:
Wolfgang Huß 2019-11-15 17:18:12 +01:00
parent d2442b73c9
commit 5c4eb36b12

View File

@ -21,38 +21,35 @@ MATCH (moderator:User)-[disabled:DISABLED]->(disabledResource)
WHERE disabledResource:User OR disabledResource:Comment OR disabledResource:Post
DELETE disabled
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
SET review.createdAt = toString(datetime()), review.updatedAt = review.createdAt, review.disable = true
SET case.id = randomUUID(), case.createdAt = toString(datetime()), case.updatedAt = case.createdAt, 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
OPTIONAL MATCH (noReporterDisabledResource:User)-[notExistingReport:REPORTED]->(disabledResource)
WHERE NOT (noReporterDisabledResource)-[notExistingReport]->(disabledResource)
OPTIONAL MATCH (disabledResourceReporter:User)-[existingReport:REPORTED]->(disabledResource)
FOREACH(disabledResource IN CASE WHEN existingReport IS NULL THEN [1] ELSE [] END |
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)
)
FOREACH(disabledResource IN CASE WHEN existingReport IS NOT NULL THEN [1] ELSE [] END |
CREATE (disabledResourceReporter)-[moveModeratorReport:REPORTED]->(case)
SET moveModeratorReport = existingReport
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;
RETURN disabledResource;
" | cypher-shell
echo "
// for REPORTED resources without DISABLED relation which are handled above, create new REPORTED-Case-FLAGGED structure
MATCH (reporter:User)-[oldReport:REPORTED]->(notDisabledResource)
WHERE notDisabledResource:User OR notDisabledResource:Comment OR notDisabledResource:Post
CREATE (reporter)-[report:REPORTED]->(case:Case)
MERGE (case)-[:FLAGGED]->(notDisabledResource)
ON CREATE SET case.id = randomUUID(), case.createdAt = toString(datetime()), case.updatedAt = case.createdAt, case.disable = false, case.closed = false
SET report = oldReport
DELETE oldReport
RETURN notDisabledResource;
" | cypher-shell