简体   繁体   中英

Database change log table not creating in Postgres environment for Liquibase

Maven Dependencies;
Spring Boot version: 2.2.3.RELEASE
Liquibase Core version: 3.8.5
Postgresql version: 42.2.9

I have a Spring Boot application that runs against a PostgreSQL 11 database which has presented with a new behavior not noticed before. When I run the update command a databasechangelog table is not getting created inside my active schema even though the databasechangeloglock table is being created. This is of course causing the run to fail for relation does not exist. However; I don't control the creation of this table and have never controlled it. The table used to create automagically just like the lock table but now it's not.

Here is how I set up my 2 primary objects for the Database and Liquibase for use by the update command.

private void setDatabase() {
    if (hasConn) {
        try {
            database = (Database) Class.forName("liquibase.database.core.PostgresDatabase").newInstance();
            database.setConnection(new JdbcConnection(getConnection()));
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            log.error("Could not return Liquibase Database Object");
            log.error(e.getMessage());
        }
    } else {
        log.warn("Connection Object not yet set!");
    }
}
private void melt() {
        this.liquibase = new Liquibase(getDatabaseChangeLog(), new ClassLoaderResourceAccessor(), getDatabase());
}
private void drinkUpdate() throws LiquibaseException {
        this.liquibase.update((String) null);
}

I have recently changed this application to be part of a multi module Maven project which changed all the version references I'm using based on the new parent POM.

My question is, if anyone has seen this behavior before and if it's related to the versions of the jars being used while processing? Why would the databasechangeloglock table generate when update runs and not the databasechangelog table? Also; it appears that the databasechangelog tables generate in my public schema just fine for each of my databases that I generate... just not in my custom schema objects which hold the bulk of my database objects.

I've looked at the debug output and found that my liquibase.Liquibase object and the corresponding liquibase.database.Database object are complete and accurate with appropriately named databasechangelog and databasechangeloglock tables specified with the current schema set to my value but the change log table refuses to generate at the same time the lock table does. Unfortunately as soon as I create the databasechangelog table manually the rest of my objects specified in the database change log are created as expected.

I believe you are not using the SpringBoot and Liquibase integration the way it was meant to be used. You should not need to call liquibase directly. In fact, that may be the reason why the creation of databasechangelog table is not created. If you configure you application:

  • make sure you fill out your application.properties with JDBC url and a pointer to your changelog
  • when you call Springboot:run the process will automatically see you have a db and changelog and will before startup run the migration.
  • If you don't want the DB migration to run at startup but instead manually, then I would use Liquibase CLI in a CICD pipeline (ex. A jenkins groovy pipeline script)

Here is a good primer on setup of Springboot with Liquibase: https://docs.liquibase.com/tools-integrations/springboot/using-springboot-with-maven.html

I also played around with it to figure out using a SpringBoot initializr: https://start.spring.io/ , adding Liquibase as a dependency

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM