The equivalent Java command for writing the SQL output is: Liquibase#update(String, Writer)
. You can invoke this method in your Spring app by subclassing SpringLiquibase
and overriding afterPropertiesSet
. For example:
@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibaseWriter();
// ...
return liquibase;
}
private static class SpringLiquibaseWriter extends SpringLiquibase {
@Override
public void afterPropertiesSet() throws LiquibaseException {
try (Connection connection = getDataSource().getConnection()) {
Liquibase liquibase = createLiquibase(connection);
Writer writer; // ... get writer
liquibase.update(getContexts(), writer);
// ...
} catch (LiquibaseException | SQLException e) {
// handle
}
super.afterPropertiesSet();
}
}
The call to update(String,Writer)
will execute your changesets without actually updating the database. The call to super.afterPropertiesSet
will actually perform the liquibase updates.
I did notice the javadoc you referred to in SpringLiquibase
that mentions the writeSqlFileEnabled
and sqlOutputDir
properties. Apparently, these were removed but the javadoc was not updated (see CORE-1104). I'm not sure the reason that these options were removed or what the intended replacements are though. I've found that liquibase logging is a bit deficient, so this approach may be useful for logging (debugging) the liquibase SQL output.