-
Hey guys, I'm developing a SaaS and I want to use the Schema-per-Tenant pattern, I read that Liquibase provided this support, I just don't know how to run the changelog in the newly created schema. Could anyone help? |
Beta Was this translation helpful? Give feedback.
Answered by
lusabo
Aug 18, 2023
Replies: 2 comments 1 reply
-
/cc @andrejpetras (liquibase), @geoand (liquibase), @gsmet (liquibase) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi guys! I did like below, but don't know if is the best approach: public void runLiquibase(String schema) throws Exception {
Map<String, Object> scopeValues = new HashMap<>();
Scope.child(scopeValues, () -> {
try (Connection connection = dataSource.getConnection()) {
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
database.setDefaultSchemaName(schema);
Liquibase liquibase = new Liquibase("db/db.changelog-tenant.yaml", new ClassLoaderResourceAccessor(), database);
liquibase.update(""); // This will update the database to the latest changelog version
} catch (Exception e) {
// Handle exceptions
throw new RuntimeException("Error running Liquibase", e);
}
});
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I improved the code above: