Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename Liquibase changelog tables with spring boot

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?

like image 566
mkhaired Avatar asked Dec 02 '22 11:12

mkhaired


2 Answers

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
like image 85
leurer Avatar answered Dec 21 '22 14:12

leurer


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;
        }
like image 29
Yury Avatar answered Dec 21 '22 13:12

Yury