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 WHERE disabledResource:User OR disabledResource:Comment OR disabledResource:Post
DELETE disabled DELETE disabled
CREATE (moderator)-[review:REVIEWED]->(case:Case)-[:FLAGGED]->(disabledResource) CREATE (moderator)-[review:REVIEWED]->(case:Case)-[:FLAGGED]->(disabledResource)
SET review.updatedAt = toString(datetime()), review.createdAt = review.updatedAt, review.disable = true SET review.createdAt = toString(datetime()), review.updatedAt = review.createdAt, review.disable = true
SET case.id = randomUUID(), case.updatedAt = toString(datetime()), case.createdAt = case.updatedAt, case.disable = true, case.closed = false 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 // if disabledResource has no report, then create a moderators default report
WITH moderator, disabledResource, case WITH moderator, disabledResource, case
//, review OPTIONAL MATCH (disabledResourceReporter:User)-[existingReport:REPORTED]->(disabledResource)
//OPTIONAL MATCH (noReporterDisabledResource:User)-[:REPORTED]->(disabledResource) FOREACH(disabledResource IN CASE WHEN existingReport IS NULL THEN [1] ELSE [] END |
//WHERE noReporterDisabledResource IS NULL CREATE (moderator)-[addModeratorReport:REPORTED]->(case)
//OPTIONAL MATCH (:User)-[notExistingReport:REPORTED]->(disabledResource) 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.'
//WHERE notExistingReport IS NULL )
OPTIONAL MATCH (noReporterDisabledResource:User)-[notExistingReport:REPORTED]->(disabledResource) FOREACH(disabledResource IN CASE WHEN existingReport IS NOT NULL THEN [1] ELSE [] END |
WHERE NOT (noReporterDisabledResource)-[notExistingReport]->(disabledResource) CREATE (disabledResourceReporter)-[moveModeratorReport:REPORTED]->(case)
CREATE (moderator)-[addModeratorReport:REPORTED]->(case) SET moveModeratorReport = existingReport
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.' DELETE existingReport
)
// if disabledResource has reports, then convert them RETURN disabledResource;
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 " | 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