I'm using Liquibase (v 3.5.3) together with Spring Boot (v 1.5.3).
I want to change liquibase changelog tables names using spring boot properties file.
The only way I found to do this is setting liquibase.databaseChangeLogTableName and liquibase.databaseChangeLogLockTableName system properties to override default table names.
Is there any alternative way to override default liquibase table names using spring boot properties file instead of setting system properties?
Since this is 1 year old and still the first google result i found for this question:
For around spring boot 2.1.x (https://github.com/spring-projects/spring-boot/issues/15544 last response) setting those properties works for me:
spring.liquibase.database-change-log-lock-table=MY_CUSTOM_DATABASECHANGELOGLOCK
spring.liquibase.database-change-log-table=MY_CUSTOM_DATABASECHANGELOG
Have the same issue and manage to resolve it by overwriting liquibase global configuration. To get databaseChangeLogTableName & databaseChangeLogLockTableName liquibase create LiquibaseConfiguration instance and initialize all default parameters, but you can overwrite those parameters using next code. Below is my Liquibase configuration file and properties.
application.properties
## Liquibase default properties
application.local.database.liquibase.tag = application-integration
application.local.database.liquibase.change.log.table.name = DATABASE_CHANGE_LOG
application.local.database.liquibase.change.log.lock.table.name = DATABASE_CHANGE_LOG_LOCK
application.local.database.liquibase.should.run = true
application.local.database.liquibase.change.log = classpath:database/application-database-changes.xml
Spring Boot configuration
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.integration.spring.SpringLiquibase;
... other dependencies...
@Configuration
public class LocalDatabaseLiquibaseConfig {
@Autowired
@Qualifier(ApplicationComponentNames.LOCAL_DATA_SOURCE)
private DataSource localDatabaseDataSource;
@Value("${application.local.database.liquibase.change.log.table.name}")
private String localDatabaseLiquibaseChangeLogTableName;
@Value("${application.local.database.liquibase.change.log.lock.table.name}")
private String localDatabaseLiquibaseChangeLogLockTableName;
@Value("${application.local.database.liquibase.tag}")
private String localDatabaseLiquibaseTag;
@Value("${application.local.database.liquibase.should.run}")
private boolean isLocalDatabaseLiquibaseShouldRun;
@Value("${application.local.database.liquibase.change.log}")
private String localDatabaseLiquibaseChangeLog;
@Bean
public SpringLiquibase liquibase() {
// Overwrite default liquibase table names by custom
GlobalConfiguration liquibaseConfiguration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
liquibaseConfiguration.setDatabaseChangeLogTableName(localDatabaseLiquibaseChangeLogTableName);
liquibaseConfiguration.setDatabaseChangeLogLockTableName(localDatabaseLiquibaseChangeLogLockTableName);
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(localDatabaseDataSource);
liquibase.setShouldRun(isLocalDatabaseLiquibaseShouldRun);
liquibase.setChangeLog(localDatabaseLiquibaseChangeLog);
liquibase.setTag(localDatabaseLiquibaseTag);
return liquibase;
}
}
Updated (Liquibase v 4.x.x)
In version 4.x.x Liquibase introduced option to overwrite table names without overwriting global configuration, now it is part of SpringLiquibase class, checkout update java configuration example.
@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(localDatabaseDataSource);
liquibase.setShouldRun(isLocalDatabaseLiquibaseShouldRun);
liquibase.setChangeLog(localDatabaseLiquibaseChangeLog);
liquibase.setTag(localDatabaseLiquibaseTag);
liquibase.setDatabaseChangeLogTable(localDatabaseLiquibaseChangeLogTableName);
liquibase.setDatabaseChangeLogLockTable(localDatabaseLiquibaseChangeLogLockTableName);
return liquibase;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With