Liquigraph can only be run twice with the following changelog:
<changelog>
<changeset id="create-node" run-always="true">
<query>CREATE (n:Node)</query>
</changeset>
</changelog>
The first time, it will record the execution with a MERGE
query equivalent to:
MATCH (changelog:__LiquigraphChangelog)
CREATE (changelog)<-[:EXECUTED_WITHIN_CHANGELOG {order: 1}]-(:__LiquigraphChangeset {id: "create-node"})
(other properties of the changeset omitted). All is well.
The second time, due to the presence of the order
property inside the MERGE
clause, it will record another execution, despite the method being called "upsert":
MATCH (changelog:__LiquigraphChangelog)
CREATE (changelog)<-[:EXECUTED_WITHIN_CHANGELOG {order: 2}]-(:__LiquigraphChangeset {id: "create-node"})
If you try to run Liquibase a third time, it will complain that you have less declared changesets than have been executed (persisted).
I think the fix is actually simple. Instead of
MATCH (changelog:__LiquigraphChangelog)
MERGE (changelog)<-[:EXECUTED_WITHIN_CHANGELOG {order: {1}}]-(changeset:__LiquigraphChangeset {id: {2}})
ON MATCH SET changeset.checksum = {3},
changeset.query = {4}
ON CREATE SET changeset.author = {5},
changeset.query = {4}
changeset.checksum = {3}
the CHANGESET_UPSERT
query should be
MATCH (changelog:__LiquigraphChangelog)
MERGE (changelog)<-[exec:EXECUTED_WITHIN_CHANGELOG]-(changeset:__LiquigraphChangeset {id: {2}})
ON MATCH SET changeset.checksum = {3},
changeset.query = {4}
ON CREATE SET changeset.author = {5},
changeset.query = {4}
changeset.checksum = {3},
exec.order = {1}
(not tested at all, though, but it's the gist of the fix).
I'll try preparing a pull request.