Neo4j Cypher LiquiGraph - 使迁移脚本幂等

Neo4j Cypher LiquiGraph - make migration script idempotent

我创建了以下 LiquiGraph 迁移脚本:

<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">

    <changeset id="initial_indexes_and_constraints" author="alex">
        <query>CREATE INDEX ON :Action(entityId)</query>
        <query>CREATE CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE</query>
    </changeset>
</changelog>

如您所见 - 我在那里添加了 2 行 - 用于 INDEXCONSTRAINT 创建。

我想让它成为幂等的 - 这样我想检查索引或约束是否不存在,然后才创建它们。

是否可以将此类验证添加到我的 LiquiGraph 迁移脚本中?如果是,请举例说明。

一般来说,不需要检查索引或约束是否存在,因为当它们已经存在时不会执行任何操作。

例如:运行以下命令一次(使用 Neo4j 浏览器):

CREATE CONSTRAINT ON ( action:Action ) ASSERT action.id IS UNIQUE

将产生此输出:

Added 1 constraint, completed after 285 ms.

运行 再次执行相同的命令将产生以下输出:

(no changes, no records)