This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Liquigraph XML->Liquibase XML migration
Fixes #447
- Loading branch information
Showing
44 changed files
with
1,240 additions
and
139 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
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
76 changes: 76 additions & 0 deletions
76
liquigraph-cli/src/main/java/org/liquigraph/cli/commands/MigrateDeclaredChangeSets.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,76 @@ | ||
/* | ||
* Copyright 2014-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.liquigraph.cli.commands; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import com.beust.jcommander.ParametersDelegate; | ||
import org.liquigraph.cli.commands.delegates.MigrationConfiguration; | ||
import org.liquigraph.cli.io.ClassLoaders; | ||
import org.liquigraph.cli.io.Files; | ||
import org.liquigraph.core.api.LiquigraphApi; | ||
import org.liquigraph.core.io.ChangelogLoader; | ||
import org.liquigraph.core.io.ClassLoaderChangelogLoader; | ||
|
||
import java.util.Objects; | ||
|
||
@Parameters(commandDescription = "Migrates the given declared change sets to Liquibase XML format") | ||
public final class MigrateDeclaredChangeSets implements LiquigraphCommand { | ||
|
||
@ParametersDelegate | ||
private final MigrationConfiguration migrationConfiguration = new MigrationConfiguration(); | ||
|
||
@Parameter( | ||
names = {"--target-directory", "-d"}, | ||
description = "Output directory path into which the Liquibase change sets will be written. " + | ||
"The output file will be named <basename>.liquibase.xml", | ||
required = true | ||
) | ||
private String targetDirectory; | ||
|
||
@Override | ||
public void accept(LiquigraphApi liquigraphApi) { | ||
liquigraphApi.migrateDeclaredChangeSets( | ||
migrationConfiguration.getChangelog(), | ||
migrationConfiguration.getExecutionContexts(), | ||
targetDirectory, | ||
getChangelogLoader() | ||
); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MigrateDeclaredChangeSets migrateLiquibase = (MigrateDeclaredChangeSets) o; | ||
return Objects.equals(migrationConfiguration, migrateLiquibase.migrationConfiguration) && | ||
Objects.equals(targetDirectory, migrateLiquibase.targetDirectory); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(migrationConfiguration, targetDirectory); | ||
} | ||
|
||
private ChangelogLoader getChangelogLoader() { | ||
return new ClassLoaderChangelogLoader( | ||
ClassLoaders.urlClassLoader( | ||
migrationConfiguration.getResourceUrl(), | ||
Files.toUrl(targetDirectory) | ||
) | ||
); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
liquigraph-cli/src/test/java/org/liquigraph/cli/LiquigraphCliOfflineIT.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,52 @@ | ||
/* | ||
* Copyright 2014-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.liquigraph.cli; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
// Integration tests that do not require any database connectivity | ||
public class LiquigraphCliOfflineIT { | ||
|
||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void migrates_to_Liquibase_change_sets() { | ||
LiquigraphCli.main(new String[]{ | ||
"migrate-declared-change-sets", | ||
"--changelog", "changelog.xml", | ||
"--target-directory", folder.getRoot().getPath() | ||
}); | ||
|
||
assertThat(new File(folder.getRoot(), "changelog.liquibase.xml")) | ||
.hasContent( | ||
"<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + | ||
"<databaseChangeLog xmlns=\"http://www.liquibase.org/xml/ns/dbchangelog\" xmlns:ext=\"http://www.liquibase.org/xml/ns/dbchangelog-ext\" xmlns:pro=\"http://www.liquibase.org/xml/ns/pro\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd\">\n" + | ||
" <changeSet author=\"you\" id=\"hello-world\" objectQuotingStrategy=\"LEGACY\">\n" + | ||
" <sql splitStatements=\"true\" stripComments=\"false\">CREATE (n:Sentence {text:'Hello monde!'}) RETURN n</sql>\n" + | ||
" </changeSet>\n" + | ||
" <changeSet author=\"you\" id=\"hello-world-fixed\" objectQuotingStrategy=\"LEGACY\">\n" + | ||
" <sql splitStatements=\"true\" stripComments=\"false\">MATCH (n:Sentence {text:'Hello monde!'}) SET n.text='Hello world!' RETURN n</sql>\n" + | ||
" </changeSet>\n" + | ||
"</databaseChangeLog>"); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.