Rename Liquibase changelog tables with spring boot

流过昼夜 提交于 2019-12-11 09:43:36

问题


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?


回答1:


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;
    }
}



回答2:


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


来源:https://stackoverflow.com/questions/49830507/rename-liquibase-changelog-tables-with-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!