I’m using Liquibase Core API to automate database deployments, I’m working on Postgres and I have an extension for it for custom functionality, I’m unable to find a way to use the extension in my Java code or I’m unable to figure out how to make it work.
public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection("ConnectionString", "UserName", "");
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Map<String, Object> scopedSettings = new LinkedHashMap<>();
scopedSettings.put(Scope.Attr.database.name(), database);
// Register PrimaryKeyChangelogHistoryService
Scope.getCurrentScope().getSingleton(ChangeLogHistoryServiceFactory.class).register(new PrimaryKeyChangelogHistoryService());
String scopeId = Scope.enter(scopedSettings);
Scope.child(scopedSettings, () -> {
CommandScope commandScope = new CommandScope(UpdateCommandStep.COMMAND_NAME);
commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.DATABASE_ARG, database);
commandScope.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "changelog/changelog-root.xml");
commandScope.execute();
});
Scope.exit(scopeId);
}
- This code works partially, but doesn’t load my Extension (Jar), should the Jar be added under resources folder?
- Can I add a reference to my Extension project instead of the Jar and make it load? (I’d prefer this more if its possible)