How to generate Index and Constraint script for Neo4j store using Liquigraph in java?

若如初见. 提交于 2019-12-04 09:55:01

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"          │
└──────────────────────────────────────────────────────────────────────┘
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!