我使用 Liquibase(v 3.5.3)和 Spring Boot(v 1.5.3)。
我想使用spring boot属性文件更改liquibase changelog表名。
我发现这样做的唯一方法是设置 liquibase.databaseChangeLogTableName 和 liquibase.databaseChangeLogLockTableName 系统属性以覆盖默认表名。
有没有其他方法可以使用spring boot属性文件覆盖默认liquibase表名而不是设置系统属性?
答案 0 :(得分:2)
遇到同样的问题并设法通过覆盖liquibase全局配置来解决它。获取 databaseChangeLogTableName & databaseChangeLogLockTableName liquibase创建 LiquibaseConfiguration 实例并初始化所有默认参数,但您可以使用下一个代码覆盖这些参数。 下面是我的Liquibase配置文件和属性。
<强> 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配置
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;
}
}
答案 1 :(得分:2)
因为这是1岁,但仍然是我针对此问题找到的第一个Google结果:
对于Spring Boot 2.1.x左右(https://github.com/spring-projects/spring-boot/issues/15544最后的响应),设置这些属性对我而言有效:
spring.liquibase.database-change-log-lock-table=MY_CUSTOM_DATABASECHANGELOGLOCK
spring.liquibase.database-change-log-table=MY_CUSTOM_DATABASECHANGELOG