Graph constraint

Description

The Graph constraint action (previously Neo4j constraint) creates or drops constraints on node or relationship properties in a graph database, in the syntax of the database: Neo4j or Memgraph. The constraint types differ per database.

For similar operations on indexes, check the Graph index action.

Options

  • Graph database connection : The name of the graph database connection to update constraints on

  • Constraint updates to perform: You can specify your list of constraint updates here

    • Update type : CREATE or DROP

    • Type of object to put constraint on: NODE or RELATIONSHIP

    • Type of constraint: UNIQUE, NOT_NULL, or NODE_KEY

    • Constraint name: The name for your constraint (mandatory)

    • Object name: the label of the node or relationship you want to update a constraint for

    • Object property: the property to put the constraint on (for NODE_KEY, use comma-separated properties like "id,name")

The constraint name, object name and properties can be variables, for example ${PERSON_KEY}. The action resolves them before it builds the statement, for create and drop, and the Cypher preview shows the resolved values.

NODE_KEY constraints are only available in Neo4j Enterprise Edition. NODE_KEY constraints require multiple properties (comma-separated) and can only be applied to nodes, not relationships.

Show Cypher Preview

The action dialog includes a "Show Cypher" button that displays a preview of the Cypher statements that will be executed for creating or dropping constraints. This preview shows the exact CREATE CONSTRAINT or DROP CONSTRAINT statements before execution.

The preview is read-only and helps you verify the constraint operations that will be performed, including the correct syntax for UNIQUE, NOT_NULL, and NODE_KEY constraints.

Result

What this action passes on to the next action. See Action results for how results travel through a workflow.

Result Value

True

All the constraint updates ran, with 0 errors. The drops run first, then the creates. An empty list is also true.

False

The action is never false: see the WARNING.

Result files

Passed on unchanged.

Result rows

Passed on unchanged.

When a constraint update can’t be done, the workflow stops with an error and no hop from the action is followed: the Graph database connection is empty, doesn’t exist or can’t be reached, an update has no Update type (a blank type comes back as CREATE when the workflow is loaded from its file), on Neo4j Constraint name is empty or a create has no Object property (a drop only uses the name), on Memgraph, which identifies a constraint by label and property, Object name or Object property is empty, or the database refuses the statement, for example NOT_NULL or NODE_KEY on Neo4j Community Edition, or a UNIQUE constraint on data that already has duplicate values. The updates before it stay done, the ones after it are not run.
On Neo4j the action creates with IF NOT EXISTS and drops with IF EXISTS. Creating a constraint that already exists, or dropping one that doesn’t, does nothing and the action is still true. This is also the case when a constraint with the same name exists on another label or property, or an equivalent one exists with another name: nothing is created.