问题
I am trying to generate the Index
and Constraint
for my spring entities. I am not using any capability of spring-data to do it such as indexes.auto=assert
.
How can I generate the scripts with following conditions
I need to generate scripts in
offline
mode. ie I cannot provide anyNeo4j
server,user,password etc.I need to use the java api to achieve it. I am able to create liquigraph change-log but I can't find a way to generate the script.
The maven dependency I have used is
<!-- https://mvnrepository.com/artifact/org.liquigraph/liquigraph-core -->
<dependency>
<groupId>org.liquigraph</groupId>
<artifactId>liquigraph-core</artifactId>
<version>3.1.0</version>
</dependency>
My output should be a file containing the scripts like these
CREATE CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE
How can I do this ?
回答1:
If you will run your changeset from Java, you don't need to put any credentials into it, just CYPHER queries.
Create changelog.xml and put in resources.
<?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>
Then you can run migration from Java, and all credentials you can keep in your application.
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);
After execution your constraint should be added, at least works for me
╒══════════════════════════════════════════════════════════════════════╕
│"description" │
╞══════════════════════════════════════════════════════════════════════╡
│"CONSTRAINT ON ( __liquigraphlock:__LiquigraphLock ) ASSERT __liquigra│
│phlock.name IS UNIQUE" │
├──────────────────────────────────────────────────────────────────────┤
│"CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE" │
└──────────────────────────────────────────────────────────────────────┘
来源:https://stackoverflow.com/questions/56254443/how-to-generate-index-and-constraint-script-for-neo4j-store-using-liquigraph-in