Skip to content

Commit

Permalink
Do not rely on relative path for deltas folder
Browse files Browse the repository at this point in the history
* The deltas folder was looked up based on the relative path of the
  programs CWD. This would fail if running the migration tool from a
  different location. Hence changed to derive the path based on the JAR
  location
  • Loading branch information
maheshp committed Jun 17, 2020
1 parent 972d96d commit d05507a
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;

import static org.apache.commons.io.FilenameUtils.separatorsToUnix;

public class DbDeploySchemaMigrator {
private final BasicDataSource sourceDataSource;
private final Connection connection;
Expand All @@ -36,8 +41,8 @@ public DbDeploySchemaMigrator(BasicDataSource sourceDataSource, Connection conne
this.connection = connection;
}

public String migrationSQL() throws SQLException, DbDeployException, IOException, ClassNotFoundException {
String deltasFolder = isH2() ? "h2deltas" : "pgdeltas";
public String migrationSQL() throws SQLException, DbDeployException, IOException, ClassNotFoundException, URISyntaxException {
String deltasFolder = deltasFolder();

InMemory inMemory = new InMemory(sourceDataSource, dbms(), new File(deltasFolder), "DDL");

Expand All @@ -62,6 +67,12 @@ private boolean isH2() throws SQLException {
return connection.getMetaData().getDatabaseProductName().equalsIgnoreCase("H2");
}

private String deltasFolder() throws SQLException, URISyntaxException {
String folder = isH2() ? "h2deltas" : "pgdeltas";
String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getParent();

return URI.create(separatorsToUnix(Paths.get(jarPath, folder).toString())).normalize().toString();
}
public static class PostgreSQLDbmsSyntax extends DbmsSyntax {
public PostgreSQLDbmsSyntax() {
}
Expand Down

0 comments on commit d05507a

Please sign in to comment.