neo4j 如何删除所有约束 [英] neo4j how to drop all constraints
问题描述
是否有一个 cypher 命令来删除所有约束?
Is there a cypher command to drop all constraints?
我知道我可以取消特定的限制.
I know I can drop specific constraints.
DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE
但是我想在测试后清除所有约束作为拆卸的一部分.在文档中找不到任何内容,但类似于:
However I want to clear all constraints as part of teardown after testing. Can't find anything in the docs, but something like:
DROP CONSTRAINT *
<小时>
更新:我的测试设置.
Update: My testing setup.
编写一个小型的基于 Promise 的 nodejs 密码客户端.我想测试在应用程序代码中定义唯一索引.
Writing a tiny promise-based nodejs cypher client. I want to test defining unique indexes in application code.
推荐答案
可以通过对 http://localhost:7474/db/data/schema/constraint/的 GET 请求获取所有索引和约束的列表
和 http://localhost:7474/db/data/schema/index
.下面是我在 Ruby 中的做法,也许它会让你对如何在 Node 中做同样的事情有一个想法.
You can get a list of all indexes and constraints through GET requests to http://localhost:7474/db/data/schema/constraint/
and http://localhost:7474/db/data/schema/index
. Here's how I do it in Ruby, maybe it'll give you an idea of how to do the same in Node.
c.after(:all) do
conn = Faraday.new(url: "http://localhost:7474")
response = conn.get('/db/data/schema/constraint/')
constraints = JSON.parse(response.body)
constraints.each do |constraint|
Neo4j::Session.query("DROP CONSTRAINT ON (label:`#{constraint['label']}`) ASSERT label.#{constraint['property_keys'].first} IS UNIQUE")
end
response = conn.get('/db/data/schema/index/')
indexes = JSON.parse(response.body)
indexes.each do |index|
Neo4j::Session.query("DROP INDEX ON :`#{index['label']}`(#{index['property_keys'].first})")
end
end
这篇关于neo4j 如何删除所有约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!