Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update constraint syntax #1238

Merged
merged 3 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ label:added[]
[source, cypher, role="noheader"]
----
CREATE CONSTRAINT [constraint_name] [IF NOT EXISTS]
ON (n:LabelName)
ASSERT (n.propertyName_1, …, n.propertyName_n) IS UNIQUE
FOR (n:LabelName)
REQUIRE (n.propertyName_1, …, n.propertyName_n) IS UNIQUE
[OPTIONS "{" option: value[, ...] "}"]
----
a|
Expand Down Expand Up @@ -125,8 +125,8 @@ a| Replaced by:
[source, cypher, role="noheader"]
----
CREATE CONSTRAINT [name]
ON (node:Label)
ASSERT node.property IS NOT NULL
FOR (node:Label)
REQUIRE node.property IS NOT NULL
----


Expand All @@ -144,8 +144,8 @@ Replaced by:
[source, cypher, role="noheader"]
----
CREATE CONSTRAINT [name]
ON ()-[rel:REL]-()
ASSERT rel.property IS NOT NULL
FOR ()-[rel:REL]-()
REQUIRE rel.property IS NOT NULL
----


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ class ConstraintsTest extends DocumentingTestBase with SoftReset {
queryText = "CREATE CONSTRAINT ON (book:Book) ASSERT book.title IS NOT NULL",
assertions = _ => hasNodeConstraint("Book", "title")
)
testQuery(
title = "Create a node property existence constraint using deprecated syntax",
Hunterness marked this conversation as resolved.
Show resolved Hide resolved
text = "The node property existence constraint ensures that all nodes " +
"with a certain label have a certain property.",
queryText = "CREATE CONSTRAINT ON (book:Book) ASSERT exists(book.title)",
assertions = _ => hasNodeConstraint("Book", "title")
)
prepareAndTestQuery(
title = "Create a node property existence constraint only if it does not already exist",
text = "If it is unknown if a constraint exists or not but we want to make sure it does, we add the `IF NOT EXISTS`. " +
Expand Down Expand Up @@ -289,6 +296,13 @@ class ConstraintsTest extends DocumentingTestBase with SoftReset {
queryText = "CREATE CONSTRAINT ON ()-[like:LIKED]-() ASSERT like.week IS NOT NULL",
assertions = _ => hasRelationshipConstraint("LIKED", "week")
)
testQuery(
title = "Create a relationship property existence constraint using deprecated syntax",
text = "The relationship property existence constraint ensures all relationships " +
"with a certain type have a certain property.",
queryText = "CREATE CONSTRAINT ON ()-[like:LIKED]-() ASSERT exists(like.week)",
assertions = _ => hasRelationshipConstraint("LIKED", "week")
)
prepareAndTestQuery(
title = "Create a relationship property existence constraint only if it does not already exist",
text = "If it is unknown if a constraint exists or not but we want to make sure it does, we add the `IF NOT EXISTS`. " +
Expand Down