Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Invalid persistence of executed changesets with run-on-change/run-always #58

Closed
fpavageau opened this issue Apr 14, 2016 · 3 comments
Closed
Labels

Comments

@fpavageau
Copy link
Contributor

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.

@fbiville
Copy link
Collaborator

Cool, thx for the report (and the future fix)!

@fbiville fbiville added the bug label Apr 14, 2016
fpavageau added a commit to fpavageau/liquigraph that referenced this issue Apr 15, 2016
The persistence of changesets has changed since RC2, which fixed the bug
reported in liquibase#58. However, there are no tests on changesets with those
attributes, and this commit fixes that.
fbiville pushed a commit that referenced this issue Apr 15, 2016
The persistence of changesets has changed since RC2, which fixed the bug
reported in #58. However, there are no tests on changesets with those
attributes, and this commit fixes that.
@fbiville
Copy link
Collaborator

I guess we can close this ;-)

@fpavageau
Copy link
Contributor Author

Definitely, if I'd checked master before filing the issue, I would have seen it was already fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants