# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
"""SQL statements that test the integrity of the database with respect to nodes."""
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from aiida.common.extendeddicts import AttributeDict
from aiida.orm import Data, CalculationNode, WorkflowNode
VALID_NODE_BASE_CLASSES = [Data, CalculationNode, WorkflowNode]
VALID_NODE_TYPE_STRING = '({})%'.format('|'.join([format_type_string_regex(cls) for cls in VALID_NODE_BASE_CLASSES]))
SELECT_NODES_WITH_INVALID_TYPE = """
SELECT node.id, node.uuid, node.node_type
FROM db_dbnode AS node
WHERE node.node_type NOT SIMILAR TO %(valid_node_types)s;
"""
INVALID_NODE_SELECT_STATEMENTS = (AttributeDict({
'sql': SELECT_NODES_WITH_INVALID_TYPE,
'parameters': {
'valid_node_types': VALID_NODE_TYPE_STRING
},
'headers': ['ID', 'UUID', 'Type'],
'message': 'detected nodes with invalid type'
}),)