1

i am trying to build services from docker-compose. In docker-compose i declare spring boot application and postgres db, for migration i am using liquibase During startup i faced with issue: as it seems to me, liquibase failed to pass second migration on one of my service and throws the error:

Reason: liquibase.exception.DatabaseException: ERROR: relation "items" does not exist

i am a bit confused since locally everything works perfect, there are no errors on migrations and database. Also second service (saleorders-service) passed OK, although there is only one migration file for it. So could anybody help or advice something or maybe faced with such issue before and know root cause of this problem?

thanks in advance for any help!

below i leave some detailed information:

docker-compose i built:

    version: "3.3"
    services:
      itemstorageDB:
        image: postgres:13
        container_name: itemstorageDB
        environment:
          POSTGRES_PASSWORD: ${PWD}
          POSTGRES_USER: ${USER}
          POSTGRES_DB: itemstorage
          POSTGRES_HOST: itemstorageDB
        ports:
          - "5433:5432"
        restart: always
        networks:
          - proxynet
  saleordersDB:
    image: postgres:13
    container_name: saleordersDB
    environment:
      POSTGRES_PASSWORD: ${PWD}
      POSTGRES_USER: ${USER}
      POSTGRES_DB: saleorders
      POSTGRES_HOST: saleordersDB
    ports:
      - "5434:5432"
    restart: always
    networks:
      - proxynet

  itemstorage-service:
    build:
      context: ./ItemStorageService
      dockerfile: Dockerfile
    container_name: itemstorage-service
    ports:
      - 8081:8081
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://itemstorageDB:5432/itemstorage?serverTimezone=UTC&createDatabaseIfNotExist=true&autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false
    restart: always
    networks:
      - proxynet
    depends_on:
      - itemstorageDB
      
  saleorders-service:
    build:
      context: ./SaleOrdersService
      dockerfile: Dockerfile
    container_name: saleorders-service
    ports:
      - 8082:8082
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://saleordersDB:5432/saleorders?serverTimezone=UTC&createDatabaseIfNotExist=true&autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false
    restart: always
    networks:
      - proxynet
    depends_on:
      - saleordersDB

networks:
  proxynet:
    external:
      name: docker_proxynet

First migration file which i suppose liqibase do not like:

--liquibase formatted sql
--changeset ek:createTables splitStatements=true endDelimiter:;

create table brands (
    id bigserial not null primary key,
    brandname varchar(255) not null,
    brandversion varchar(255) not null,
    creationdate TIMESTAMP,
    constraint unique_bname unique (brandname)
);
--rollback DROP TABLE
--rollback brands
create table items(
    id bigserial not null primary key,
    serial bigint not null,
    item_type varchar(255) not null,
    brand_id bigint not null,
    parent_id bigint,
    childcount bigint,
    creationdate TimeStamp,
    constraint brandId_id_fk foreign key (brand_id) references brands (id),
    constraint parent_id_fk foreign key (parent_id) references items (id)
);
--rollback DROP TABLE
--rollback items
create table brandspage(
    id bigserial not null primary key,
    openpagedate TimeStamp
);
--rollback DROP TABLE
--rollback brandspage

Second migration file where failure occured:

--liquibase formatted sql
--changeset ek:insert-initData-into-BrandAndItemTable splitStatements=true endDelimiter:;

INSERT INTO brands (id, brandname, brandversion, creationdate) VALUES (1, 'gucci', '0.1', '2021-12-04 09:11:26');
INSERT INTO brands (id, brandname, brandversion, creationdate) VALUES (4, 'cc', '0.1', '2021-12-07 15:45:22');
INSERT INTO brands (id, brandname, brandversion, creationdate) VALUES (8, 'kiton', '0.1', '2021-12-13 15:02:31');

Stack trace on start up:

itemstorage-service    | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for change set db/changelog/changeSet/insert-initData-into-ItemTable.sql::insert-initData-into-ItemTable::ek:
itemstorage-service    |      Reason: liquibase.exception.DatabaseException: ERROR: relation "items" does not exist
itemstorage-service    |   Position: 13 [Failed SQL: (0) INSERT INTO items (id, serial, item_type, brand_id, parent_id, creationdate) VALUES (72, 100, 'PACK', 4, null, '2021-12-26 06:28:55')]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar!/:2.6.2]
itemstorage-service    |    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar!/:2.6.2]
itemstorage-service    |    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar!/:2.6.2]
itemstorage-service    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar!/:2.6.2]
itemstorage-service    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar!/:2.6.2]
itemstorage-service    |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar!/:2.6.2]
itemstorage-service    |    at com.marketplace.itemstorageservice.ItemStorageServiceApplication.main(ItemStorageServiceApplication.java:15) ~[classes!/:na]
itemstorage-service    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
itemstorage-service    |    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
itemstorage-service    |    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
itemstorage-service    |    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
itemstorage-service    |    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[itemStorageService-0.1.jar:na]
itemstorage-service    |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[itemStorageService-0.1.jar:na]
itemstorage-service    |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[itemStorageService-0.1.jar:na]
itemstorage-service    |    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[itemStorageService-0.1.jar:na]
itemstorage-service    | Caused by: liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for change set db/changelog/changeSet/insert-initData-into-ItemTable.sql::insert-initData-into-ItemTable::ek:
itemstorage-service    |      Reason: liquibase.exception.DatabaseException: ERROR: relation "items" does not exist
itemstorage-service    |   Position: 13 [Failed SQL: (0) INSERT INTO items (id, serial, item_type, brand_id, parent_id, creationdate) VALUES (72, 100, 'PACK', 4, null, '2021-12-26 06:28:55')]
itemstorage-service    |    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:124) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Liquibase.lambda$null$0(Liquibase.java:265) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.lambda$child$0(Scope.java:177) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:186) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:176) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:155) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:239) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Liquibase.lambda$update$1(Liquibase.java:264) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.lambda$child$0(Scope.java:177) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:186) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:176) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Scope.child(Scope.java:155) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Liquibase.runInScope(Liquibase.java:2404) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Liquibase.update(Liquibase.java:211) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.Liquibase.update(Liquibase.java:197) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:314) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:269) ~[liquibase-core-4.5.0.jar!/:na]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.14.jar!/:5.3.14]
itemstorage-service    |    ... 26 common frames omitted
  • This post has some similar errors and describes this error as often being caused by using mixed cases. I don't see that in what you've provided, but take a look and see if this helps you find a solution: https://stackoverflow.com/questions/695289/cannot-simply-use-postgresql-table-name-relation-does-not-exist – tabbyfoo Jun 06 '22 at 19:55

0 Answers0