forked from liquibase/liquibase-neo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export Liquigraph ChangeLog to Liquibase main class #9
- Loading branch information
1 parent
0ad01e9
commit 342e97f
Showing
3 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/liquibase/ext/neo4j/liquigraph/ChangelogExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package liquibase.ext.neo4j.liquigraph; | ||
|
||
import liquibase.change.core.RawSQLChange; | ||
import liquibase.changelog.ChangeSet; | ||
import liquibase.serializer.ChangeLogSerializer; | ||
import liquibase.serializer.ChangeLogSerializerFactory; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.liquigraph.core.io.xml.ChangelogParser; | ||
import org.liquigraph.core.io.xml.ChangelogPreprocessor; | ||
import org.liquigraph.core.io.xml.ClassLoaderChangelogLoader; | ||
import org.liquigraph.core.io.xml.ImportResolver; | ||
import org.liquigraph.core.io.xml.XmlSchemaValidator; | ||
import org.liquigraph.core.model.Changeset; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Poc for exporting Liquigraph changelog to Liquibase | ||
* TODO ==> Post a condition + Check Liquigraph in classpath.... | ||
*/ | ||
public class ChangelogExporter { | ||
|
||
public static void main(String[] args) throws IOException { | ||
ChangeLogSerializerFactory changeLogSerializerFactory = ChangeLogSerializerFactory.getInstance(); | ||
|
||
ChangeLogSerializer changeLogSerializer = changeLogSerializerFactory.getSerializer("xml"); | ||
|
||
Collection<Changeset> liquigraphChangeSets = getLiquigraphChangeSets(); | ||
|
||
List<ChangeSet> changeSets = convertChangeSets(liquigraphChangeSets); | ||
changeLogSerializer.write(changeSets, System.out); | ||
} | ||
|
||
@NotNull | ||
private static Collection<Changeset> getLiquigraphChangeSets() { | ||
ChangelogParser changelogParser = new ChangelogParser(new XmlSchemaValidator(), new ChangelogPreprocessor(new ImportResolver())); | ||
return changelogParser.parse(ClassLoaderChangelogLoader.currentThreadContextClassLoader(), "liquigraph-changelog.xml"); | ||
} | ||
|
||
@NotNull | ||
private static List<ChangeSet> convertChangeSets(Collection<Changeset> liquigraphChangeSets) { | ||
return liquigraphChangeSets.stream().map(ChangelogExporter::from).collect(Collectors.toList()); | ||
} | ||
|
||
@NotNull | ||
private static ChangeSet from(Changeset changeset) { | ||
ChangeSet liquibaseChangeSet = new ChangeSet(changeset.getId(), changeset.getAuthor(), changeset.isRunAlways(), | ||
changeset.isRunOnChange(), null, String.join(",", | ||
changeset.getExecutionsContexts()),null, null); | ||
changeset.getQueries().stream().map(RawSQLChange::new).forEach(liquibaseChangeSet::addChange); | ||
return liquibaseChangeSet; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?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="hello-world" author="you"> | ||
<query>CREATE (n:Sentence {text:'Hello monde!'}) RETURN n</query> | ||
</changeset> | ||
<changeset id="hello-world-fixed" author="you"> | ||
<query>MATCH (n:Sentence {text:'Hello monde!'}) SET n.text='Hello world!' RETURN n</query> | ||
</changeset> | ||
</changelog> |