我正在尝试为我的弹簧实体生成Index
和Constraint
。我没有使用诸如indexes.auto=assert
之类的spring-data功能。
如何在以下条件下生成脚本
我需要以offline
模式生成脚本。即我不能提供任何Neo4j
服务器,用户,密码等。
我需要使用Java api来实现它。我可以创建液体记录仪更改日志,但找不到生成脚本的方法。
我使用的Maven依赖项是
<!-- https://mvnrepository.com/artifact/org.liquigraph/liquigraph-core -->
<dependency>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-core</artifactId>
<version>3.1.0</version>
</dependency>
我的输出应为包含此类脚本的文件
CREATE CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE
我该怎么做?
答案 0 :(得分:1)
如果要从Java运行更改集,则无需在其中放入任何凭据,只需进行CYPHER查询即可。
创建 changelog.xml 并放入资源。
<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
<changeset id="action-contraint" author="JITHIN">
<query>CREATE CONSTRAINT ON (action:Action) ASSERT action.id IS UNIQUE</query>
</changeset>
</changelog>
然后,您可以从 Java 运行迁移,并保留所有可以保存在应用程序中的凭据。
Configuration configuration = new ConfigurationBuilder()
.withMasterChangelogLocation("changelog.xml")
.withUri("jdbc:neo4j:http://localhost:7474")
.withUsername(user)
.withPassword(pass)
.withRunMode()
.build();
Liquigraph liquigraph = new Liquigraph();
liquigraph.runMigrations(configuration);
执行后,应该添加约束,至少对我有用
╒══════════════════════════════════════════════════════════════════════╕
│"description" │
╞══════════════════════════════════════════════════════════════════════╡
│"CONSTRAINT ON ( __liquigraphlock:__LiquigraphLock ) ASSERT __liquigra│
│phlock.name IS UNIQUE" │
├──────────────────────────────────────────────────────────────────────┤
│"CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE" │
└──────────────────────────────────────────────────────────────────────┘