Liquibase exception "relation already exists" after data migration

Hi,

I am currently testing deployment on AWS which works flawlessly when using an empty database to begin with. However, when I migrate data from the database on the local development machine to the AWS database, I keep getting liquibase exceptions of the form:

liquibase.exception.DatabaseException: ERROR: relation “user_” already exists

Postgres is being used on the development machine as well as on AWS, both times in docker with the same image. The data is being migrated by first using a dump from the local development machine using

docker exec postgresdb pg_dump --clean -U user -d database > /home/db.sql

and then importing it on AWS using

docker exec postgresdb psql -U user -d database -f /home/db.sql

The migration of the data takes place flawlessly and the databases look exactly the same on the local development machine and on AWS.

When the Jmix application is started on the local development machine, no liquibase exceptions are thrown. But when starting the application on AWS, the above mentioned liquibase exceptions (“relation already exists”) are thrown for each table. Why is this happening and what would be the solution to this?

Thank you.

How is your application packaged when run on AWS? Is it built as a docker image using bootBuildImage?

Yes, packaged using bootBuildImage and then run on an EC2 instance.

Most probably it’s because when running in docker container built with bootBuildImage, Liquibase determines the path to changelog differently, for example:
BOOT-INF/classes/com/company/demo/liquibase/changelog/010-init-user.xml

At the same time when run from IDE or from executable JAR built by bootJar, the path doesn’t contain BOOT-INF/classes.

So if you created the database not by the application in docker, the database contains information about executed changelogs with correct paths. If afterwards you run the application in docker with the same database, Liquibase tries to execute the same chagelogs because they have different paths.

The problem is registered in the Liquibase issue: Inconsistent changelog filename after updating to 4.3.1 · Issue #1755 · liquibase/liquibase · GitHub
It has a workaround: in main changelog.xml, use <include file="..."/> for each file instead of <includeAll path="/com/company/demo/liquibase/changelog"/>, which is of course inconvenient.

If you don’t use this workaround, you should not connect application running in docker and differently to the same database.

1 Like

Or you can do this:

update databasechangelog
  set 
       filename= replace (
	       filename,
		   'BOOT-INF/classes/',
		   ''
		);

Anyway I see that after 9 months this bug is still open.