Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FormattedSqlChangeLogParser reusable #2569

Merged
merged 4 commits into from
Mar 1, 2022
Merged

Make FormattedSqlChangeLogParser reusable #2569

merged 4 commits into from
Mar 1, 2022

Conversation

clarenced
Copy link

@clarenced clarenced commented Feb 22, 2022

Description

Currently the FormattedSqlChangeLogParser's supports() method is hard-coded to only support files that end in .sql. This makes it difficult for extensions to subclass to leverage the logic in FormattedSqlChangeLogParser but use a different extension. In this case, to have use formatted *.cypher files for neo4j

@fbiville
Copy link
Contributor

Hello, I paired with @clarenced on this during today's https://www.meetup.com/Paris-Hackergarten/ :)
This is needed for liquibase/liquibase-neo4j#144.

nvoxland and others added 2 commits February 22, 2022 15:16
…l/FormattedSqlChangeLogParser.java

Co-authored-by: Florent Biville <445792+fbiville@users.noreply.github.com>
@nvoxland
Copy link
Contributor

The change seems good.

It's a refactoring that improves extensibility, and the existing automated tests would catch any issue with it not detecting formatted changelog files correctly.

@nvoxland nvoxland changed the base branch from master to 1_9 February 24, 2022 15:10
@nvoxland nvoxland changed the base branch from 1_9 to master February 24, 2022 15:10
@XDelphiGrl XDelphiGrl assigned XDelphiGrl and unassigned nvoxland Feb 24, 2022
@XDelphiGrl
Copy link
Contributor

This PR, in association with the liquibase-neo4j PR, introduces the ability to use Liquibase to deploy changelogs in the native Neo4j cypher format.

Special Thanks!
Thank you, @clarenced and @fbivill for this PR and having a good set of tests in the liquibase-neo4j extension. As my first ever liquibase-neo4j testing, this was fun for me.

Note
The liquibase-neo4j extension did not load unless I had my ${LIQUIBASE_HOME} defined in my $PATH. I do not know why this is but if you see errors that the driver org.neo4j.jdbc.bolt.BoltDriver cannot be located when the driver jar is in the ${LIQUIBASE_HOME}\lib directory, troubleshoot by running:

liquibase --log-level FINE --log-file out.txt update-sql [anyChangelog].

If the debug output does not show that the Neo4jDatabase loaded, you may want to check your $PATH contains ${LIQUIBASE_HOME}.

Debug Output if Extension Loaded Correctly

[liquibase.servicelocator] Loaded liquibase.database.Database instance liquibase.ext.neo4j.database.Neo4jDatabase


Test Setup

  • Start a neo4j database (I used Neo4j Desktop for Windows)
  • Drop the liquibase-neo4j extension in ${LIQUIBASE_HOME}\lib
  • Drop the Neo4j driver in ${LIQUIBASE_HOME}\lib
    • The driver class is: 'org.neo4j.jdbc.bolt.BoltDriver'
  • Configure liquibase.properties file to connect to your Neo4j database:
#### Target Connection ####
url: jdbc:neo4j:bolt://localhost:7687
username: neo4j
password: password

Verify update-sql correctly outputs generated SQL for a formatted .cipher changelog. PASS

-- *********************************************************************
-- Update Database Script
-- *********************************************************************
-- Change Log: neo4j-changelog.xml
-- Ran at: 2/28/22, 12:13 PM
-- Against: neo4j@jdbc:neo4j:bolt://localhost:7687
-- Liquibase version: [Core: //liquibase-neo4j-117/1609/d4b007/2022-02-22 21:26+0000, Pro: master/645/8151fa/2022-02-22T15:44:50Z]
-- *********************************************************************

CREATE CONSTRAINT `unique_liquibase_lock` ON (n:`__LiquibaseLock`) ASSERT n.`lockedBy` IS UNIQUE;

CREATE (lock:__LiquibaseLock {id: '0947eeab-8e50-420e-b67d-b8a955242878', grantDate: DATETIME(), lockedBy: 'Neo4jLockService'});

CREATE CONSTRAINT `unique_liquibase_tag` ON (n:`__LiquibaseTag`) ASSERT n.`tag` IS UNIQUE;

CREATE CONSTRAINT `unique_liquibase_context` ON (n:`__LiquibaseContext`) ASSERT n.`context` IS UNIQUE;

CREATE CONSTRAINT `unique_liquibase_label` ON (n:`__LiquibaseLabel`) ASSERT n.`label` IS UNIQUE;

CREATE CONSTRAINT `node_key_liquibase_change_set` ON (n:`__LiquibaseChangeSet`) ASSERT (n.`id`, n.`author`, n.`changeLog`) IS NODE KEY;

MERGE (changeLog:__LiquibaseChangeLog)    ON CREATE SET changeLog.dateCreated = DATETIME()    ON MATCH SET changeLog.dateUpdated = DATETIME();

CREATE CONSTRAINT `unique_liquibase_lock` ON (n:`__LiquibaseLock`) ASSERT n.`lockedBy` IS UNIQUE;

-- Changeset neo4j-changelog.xml::my-movie-init::fbiville
-- Creates a forgettable movie
CREATE (:Movie {title: 'My Life'});

MATCH (changeLog:__LiquibaseChangeLog) SET changeLog.dateUpdated = DATETIME() CREATE (changeSet:__LiquibaseChangeSet {   changeLog: 'neo4j-changelog.xml',    id: 'my-movie-init',   author: 'fbiville',   checkSum: '8:a574a03f600a80f9acdda70b678afbc4',   execType: 'EXECUTED',    description: 'cypher',    comments: 'Creates a forgettable movie',    deploymentId: '6071987835',    storedChangeLog: 'neo4j-changelog.xml',    liquibaseVersion: 'DEV' })-[:IN_CHANGELOG {   dateExecuted: DATETIME(),    orderExecuted: 1 }]->(changeLog);

MATCH (changeSet:__LiquibaseChangeSet {id: 'my-movie-init', author: 'fbiville', changeLog: 'neo4j-changelog.xml' })-[:IN_CHANGELOG]->(:__LiquibaseChangeLog) OPTIONAL MATCH (changeSet)<-[c:CONTEXTUALIZES]-(:__LiquibaseContext) DELETE c WITH changeSet OPTIONAL MATCH (changeSet)<-[l:LABELS]-(:__LiquibaseLabel) DELETE l;

MATCH (lock:__LiquibaseLock {id: '0947eeab-8e50-420e-b67d-b8a955242878'}) DELETE lock;

Logs saved to C:\Users\erz\work\DaticalDB-testing\liquibase-pro-cli-project\neo4j\out.txt
Liquibase command 'update-sql' was executed successfully

Verify update correctly deploys changesets in a formatted .cipher changelog to a Neo4j database. PASS

Liquibase History for jdbc:neo4j:bolt://localhost:7687

- Database updated at 2/28/22, 12:15 PM. Applied 1 changeset(s), DeploymentId: 6072156353
  changelog.cypher::count-movies::fbiville

Liquibase command 'history' was executed successfully.

Test Environment
Liquibase Core liquibase-neo4j-117/1609/d4b007, Pro: master/645/8151fa
liquibase-neo4j (local build) liquibase-neo4j-4.7.1.4 from branch clarenced:liquibase-neo4j-1176
Neo4J 4.4.3
Windows 10
Passing Functional Tests

@fbiville
Copy link
Contributor

fbiville commented Mar 3, 2022

@XDelphiGrl thanks for the thorough test. As for the JAR issue, I believe this is a consequence of a misconfiguration of the "full" JAR creation, which has been fixed today with this release: https://github.com/liquibase/liquibase-neo4j/releases/tag/liquibase-neo4j-4.8.0.1.

@XDelphiGrl
Copy link
Contributor

@fbiville, you are very welcome! I will try with the latest build and let you know what I see. I hope you, your family and friends are safe and healthy in this stressful time.

@kataggart kataggart modified the milestones: On Deck, NEXT Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants