Multi-Store Liquibase Configuration Issue - Schema Not Being Recognized

Problem Summary:
I’m implementing a multi-data store configuration in my Jmix application with a primary store and an additional “digital” store. The digital store Liquibase is failing with a schema not found error.
Environment:

  • Jmix version: 1.7.1
  • Database: PostgreSQL

Current Configuration:
DigitalStoreConfiguration.java:
package com.mcollect.digital.config;

@Slf4j
@Configuration
public class DigitalStoreConfiguration {

@Bean
@ConfigurationProperties(prefix = "digital.datasource")
DataSource digitalDataSource() {
    return DataSourceBuilder.create().build();
}

@Bean
JmixEntityManagerFactoryBean digitalEntityManagerFactory(
        @Qualifier("digitalDataSource") DataSource dataSource,
        JpaVendorAdapter jpaVendorAdapter,
        DbmsSpecifics dbmsSpecifics,
        JmixModules jmixModules,
        Resources resources) {
    return new JmixEntityManagerFactoryBean("digital", dataSource, jpaVendorAdapter,
            dbmsSpecifics, jmixModules, resources);
}
@Bean
public JdbcTemplate digitalJdbcTemplate(@Qualifier("digitalDataSource") DataSource dataSource) {
    return new JdbcTemplate(dataSource);
}
@Bean
JpaTransactionManager digitalTransactionManager(
        @Qualifier("digitalEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
    return new JmixTransactionManager("digital", entityManagerFactory);
}

@Bean
@ConditionalOnProperty(name = "digital.liquibase.enabled", havingValue = "true")
public SpringLiquibase digitalLiquibase(
        @Qualifier("digitalDataSource") DataSource dataSource) {

    SpringLiquibase liquibase = new SpringLiquibase();
    liquibase.setDataSource(dataSource);
    liquibase.setChangeLog("classpath:/com/mcollect/digital/liquibase/changelog.xml");
    liquibase.setContexts("digital");
    liquibase.setDefaultSchema("digital_addon");
    liquibase.setLiquibaseSchema("digital_addon");
    log.info("Configuring digital Liquibase with schema: digital_addon");
    return liquibase;
}

}

module.properties:

PostgreSQL digital configuration

digital.datasource.jdbc-url=jdbc:postgresql://1.1.1:5432/db?currentSchema=digital_addon
digital.datasource.username=dev
digital.datasource.password=dev

digital.datasource.driver-class-name=org.postgresql.Driver
digital.datasource.hikari.connection-timeout=20000
digital.datasource.hikari.maximum-pool-size=5
spring.quartz.auto-startup=false

jmix.liquibase.update.enabled=false
jmix.core.additional-stores=digital
jmix.data.stores = digital

Enable digital Liquibase

digital.liquibase.enabled=true
jmix.liquibase.contexts=main

Error
Caused by: liquibase.exception.LockException: liquibase.exception.DatabaseException:
ERROR: schema “digital_addon” does not exist
Position: 14 [Failed SQL: (0) CREATE TABLE digital_addon.databasechangeloglock
(ID INTEGER NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP WITHOUT TIME ZONE,
LOCKEDBY VARCHAR(255), CONSTRAINT databasechangeloglock_pkey PRIMARY KEY (ID))]

Observations:

  1. The primary store works correctly with its schema (digital_modularization_primary )
  2. The log shows: Configuring digital Liquibase with schema: digital_addon
  3. Liquibase attempts to create the tracking table with fully qualified name digital_addon.databasechangeloglock
  4. Despite the schema existing, PostgreSQL reports “schema does not exist”

Questions:

  1. Why isn’t Liquibase recognizing the existing schema even though it exists in the database?
  2. Is there a specific Jmix configuration required for additional store schemas?
  3. Should the schema be created programmatically before Liquibase starts?
  4. Are there any known issues with PostgreSQL schema resolution in multi-store configurations?

Additional Context:

  • The primary store uses the same database but a different schema
  • The database user has permissions to create tables in the digital_addon schema
  • The schema name is correctly cased (all lowercase)

Any insights or solutions would be greatly appreciated!

Hi, Puneet!

The issue occurs because the digital_addon schema does not actually exist in the PostgreSQL database when Liquibase tries to initialize. Here are the most probable causes:

  1. Schema not pre-created: PostgreSQL requires schemas to be explicitly created before use. Unlike some databases, PostgreSQL won’t automatically create a schema just because it’s specified in the Liquibase configuration.
  2. Connection string parameter ineffective: The currentSchema=digital_addon parameter in your JDBC URL only sets the search path for the session; it doesn’t create the schema or validate its existence.

Solution: The schema must be created either manually in the database or programmatically before Liquibase initialization.