Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Liquibase's XMLChangeLogSAXParser now gets the Resource instead of an…
Browse files Browse the repository at this point in the history
… InputStream, LiquibaseMigrate adapted to these changes.
  • Loading branch information
softqwewasdfortnox committed Nov 8, 2022
1 parent f7a7fe5 commit 9c18df2
Showing 1 changed file with 3 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@
import liquibase.ext.TimeoutLockService;
import liquibase.lockservice.LockServiceFactory;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.InputStreamList;
import se.fortnox.reactivewizard.db.DbDriver;

import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

Expand All @@ -52,17 +47,10 @@ public LiquibaseMigrate(LiquibaseConfig liquibaseConfig) throws LiquibaseExcepti

TimeoutLockService.setRenewalConnectionCreator(() -> createDatabaseConnectionFromConfiguration(liquibaseConfig));

liquibaseList = new ArrayList<>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
String file = url.toExternalForm();
int jarFileSep = file.lastIndexOf('!');
String loggedFileName = file.substring(jarFileSep + 1);
Liquibase liquibase = new Liquibase(loggedFileName, new UrlAwareClassLoaderResourceAccessor(file), conn);
liquibase.getDatabase().setDefaultSchemaName(liquibaseConfig.getSchema());
Liquibase liquibase = new Liquibase(liquibaseConfig.getMigrationsFile(), new ClassLoaderResourceAccessor(), conn);
liquibase.getDatabase().setDefaultSchemaName(liquibaseConfig.getSchema());
liquibaseList = List.of(liquibase);

liquibaseList.add(liquibase);
}
}

private Database createDatabaseConnectionFromConfiguration(LiquibaseConfig configuration) {
Expand Down Expand Up @@ -151,35 +139,4 @@ public void rollback() throws LiquibaseException {
void exit() {
System.exit(0);
}

class UrlAwareClassLoaderResourceAccessor extends ClassLoaderResourceAccessor {
private final String realFileName;

public UrlAwareClassLoaderResourceAccessor(String realFileName) {
this.realFileName = realFileName;
}

@Override
public InputStreamList openStreams(String relativeTo, String path) throws IOException {
if (realFileName.endsWith(path)) {
path = realFileName;
}

if (path.startsWith("file:") || path.startsWith("jar:file:")) {
URL url = new URL(path);
InputStream resourceAsStream = url.openStream();
InputStreamList inputStreamList = new InputStreamList();
URI uri;
try {
uri = url.toURI();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
inputStreamList.add(uri, resourceAsStream);

return inputStreamList;
}
return super.openStreams(relativeTo, path);
}
}
}

0 comments on commit 9c18df2

Please sign in to comment.