Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Data integrity check

Garbash edited this page Oct 16, 2013 · 11 revisions

To verify that data isn't breaking the data structure we are implementing an API that scans neo4j for inconsistencies:

Check data for inconsistencies

  • Check that all resources have CREATED_BY relations:

START resource=node(*)
WHERE has(resource.nodeType)
AND (resource.nodeType="kn_Post")
AND NOT (resource)-[:CREATED_BY]-()
RETURN resource

  • Check that a connection is related to two resources: START connection=node(*)
    WHERE has(connection.nodeType)
    AND (connection.nodeType="kn_Edge")
    AND NOT ()-[:RELATED_TO]-(connection)-[:RELATED_TO]-()
    RETURN connection

  • Check that all connection have CREATED_BY relations:
    START connection=node(*)
    WHERE has(connection.nodeType)
    AND (connection.nodeType="kn_Edge")
    AND NOT (connection)-[:CREATED_BY]-()
    RETURN connection

  • Check that a comment is related to a connection: START comment=node(*)
    WHERE has(comment.nodeType)
    AND (comment.nodeType="kn_Comment")
    AND NOT (comment)-[:COMMENT_OF]-()
    RETURN comment

  • Check that a comment is related to a user: START comment=node(*)
    WHERE has(comment.nodeType)
    AND (comment.nodeType="kn_Comment")
    AND NOT (comment)-[:CREATED_BY]-()
    RETURN comment

Deletion of corrupted data:

  • DELETE resources that don't have CREATED_BY relations: START resource=node(*)
    MATCH (resource)-[relation?]-()
    WHERE has(resource.nodeType)
    AND (resource.nodeType="kn_Post")
    AND NOT (resource)-[:CREATED_BY]-()
    DELETE resource, relation

  • DELETE connections not related to two resources: START connection=node(*)
    MATCH (connection)-[relation?]-()
    WHERE has(connection.nodeType)
    AND (connection.nodeType="kn_Edge")
    AND NOT ()-[:RELATED_TO]-(connection)-[:RELATED_TO]-()
    DELETE connection, relation

  • DELETE all connection without CREATED_BY relations:
    START connection=node(*)
    MATCH (connection)-[relation?]-()
    WHERE has(connection.nodeType)
    AND (connection.nodeType="kn_Edge")
    AND NOT (connection)-[:CREATED_BY]-()
    DELETE connection, relation

  • DELETE comments without COMMENT_OF relation: START comment=node(*)
    MATCH (comment)-[relation?]-()
    WHERE has(comment.nodeType)
    AND (comment.nodeType="kn_Comment")
    AND NOT (comment)-[:COMMENT_OF]-()
    DELETE comment, relation

  • DELETE comment without CREATED_BY relation: START comment=node(*)
    MATCH (comment)-[relation?]-()
    WHERE has(comment.nodeType)
    AND (comment.nodeType="kn_Comment")
    AND NOT (comment)-[:CREATED_BY]-()
    DELETE comment, relation

Clone this wiki locally