here is spring bean config :
@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setChangeLog("classpath:db-changelog.xml");
liquibase.setDataSource(dataSource());
return liquibase;
}
and xml config from [liquibase - web site][1]
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="myDataSource" />
<property name="changeLog" value="classpath:db-changelog.xml" />
<!--
contexts specifies the runtime contexts to use.
-->
<property name="contexts" value="test, production" />
from source : SpringLiquibase -- it's code execute update , it's default behaviour .
protected void performUpdate(Liquibase liquibase) throws LiquibaseException{
if (tag != null) {
liquibase.update(tag, new Contexts(getContexts()), new LabelExpression(getLabels()));
} else {
liquibase.update(new Contexts(getContexts()), new LabelExpression(getLabels()));
}
}
class Liquibase has method
public DiffResult diff(Database referenceDatabase,
Database targetDatabase,
CompareControl compareControl)
so , you can create custom SpringLiquibase and use diff instead of update
public class MyDiffSpringLiquibase extends SpringLiquibase {
@Override
protected void performUpdate(Liquibase liquibase) throws LiquibaseException {
Database referenceDatabase = new MySQLDatabase();
referenceDatabase.setConnection();
Database targetDatabase = new MySQLDatabase();
targetDatabase.setConnection();
CatalogAndSchema catalogAndSchemaReference = new CatalogAndSchema();
CatalogAndSchema catalogAndSchemacomparison = new CatalogAndSchema();
Set<Class<? extends DatabaseObject>> finalCompareTypes = null;
Class<? extends DatabaseObject>[] snapshotTypes = new Class[]{Table.class ,View.class......};
if (snapshotTypes != null && snapshotTypes.length > 0) {
finalCompareTypes = new HashSet<Class<? extends DatabaseObject>>(Arrays.asList(snapshotTypes));
}
CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[]{new CompareControl.SchemaComparison(catalogAndSchemaReference, catalogAndSchemacomparison)}, finalCompareTypes);
liquibase.diff(referenceDatabase, targetDatabase, compareControl);
}
}
and register it as bean
@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new MyDiffSpringLiquibase ();
liquibase.setChangeLog("classpath:db-changelog.xml");
liquibase.setDataSource(dataSource());
return liquibase;
}