I have a Spring Boot project running off PostgreSQL.
My entities are defined using JPA annotations
I integrated Liquibase 4.20 in my gradle build using the plugin org.liquibase.gradle
I use generateChangeLog task to create the initial changelog, which I put in src/main/resources/db/changelog
I use gradle plugin docker-compose to start a new docker container running PostgreSQL
I use the existing changeset in src/main/resources/db/changelog, to get the current schema in to the new PostgreSQL instance
I run diffChangeLog task, to compare the JPA Entities in my source code with the fresh installed schema in PostgreSQL, and generate a diff changelog.
I would expect this diffChangeLog to be empty, because my entities have not changed since I generated the changeset in src/main/resources/db/changelog. Instead it generates a change for some of the columns in the schema, with an unnecessary modifyDataType operation.
As you can see, column “city” is data type “varchar(255)”, both in the original and the diff changesets, and also in the PostgreSQL schema. A modifyDataType change has been generated that does not change the type.
I have been trying to get this to work as expected for 2 days now, and I am stumped. I’m guessing that there is something missing or wrongly configured in a type map somewhere, and the diffChangeLog operation is reading different data types from postgreSQL than what is generated by the Hibernate dialect, so it is incorrectly identifying a change. It then generates a new change, and takes the changed data type from the JPA Entity, which is identical again.
[2023-04-07 14:53:16] INFO [liquibase.integration] Starting command execution.
[2023-04-07 14:53:17] INFO [liquibase.ext] Reading hibernate configuration hibernate:spring:com.acroteq.food.ordering.system.order.service.data.access?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
[2023-04-07 14:53:17] INFO [liquibase.ext] Found package com.acroteq.food.ordering.system.order.service.data.access
[2023-04-07 14:53:18] INFO [liquibase.ext] Using dialect org.hibernate.dialect.PostgreSQLDialect
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_addresses
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_addresses
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_items
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_items
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table orders
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table orders
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_items
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_items
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table OrderEntity_failureMessages
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table OrderEntity_failureMessages
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_items
[2023-04-07 14:53:18] INFO [liquibase.ext] Found primary key order_itemsPK
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column id bigint
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column productId bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column quantity integer
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column order_id bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column id bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table orders
[2023-04-07 14:53:18] INFO [liquibase.ext] Found primary key ordersPK
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column id bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column customerId bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column orderStatus varchar(255)
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column priceAmount numeric(38, 2)
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column priceCurrencyId bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column restaurantId bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column trackingId bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table order_addresses
[2023-04-07 14:53:18] INFO [liquibase.ext] Found primary key order_addressesPK
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column id bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column city varchar(255)
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column postalCode varchar(255)
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column street varchar(255)
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column order_id bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found table OrderEntity_failureMessages
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column OrderEntity_id bytea
[2023-04-07 14:53:18] INFO [liquibase.ext] Found column failureMessages varchar(255)
[2023-04-07 14:53:18] INFO [liquibase.database] Set default schema name to public
[2023-04-07 14:53:18] INFO [liquibase.diff] changeSets count: 7
[2023-04-07 14:53:18] INFO [liquibase.diff] ./build/liquibase/changelog_diff.yaml does not exist, creating and adding 7 changesets.
[2023-04-07 14:53:18] WARNING [liquibase.resource] Failed to create parent directories for file build\liquibase\changelog_diff.yaml
I don’t have the answer, but i wanted to let you know, that i have exact the same problem using “mvn liquibase:diff” in a maven spring boot solution using the latest liquibase 4.20 and hibernate6. in the changelog (.sql) it generates the following redundant column type changes for every property of the Entity:
ALTER TABLE users ALTER COLUMN username TYPE VARCHAR(255) USING (username::VARCHAR(255));
Even after applying this changelog using mvn liquibase:update this changes are generated again
With version 4.19.0 of liquibase + maven plugin everythink works fine!
This was my first Liquibase implementation (in this project), and I did not think to try a previous version. I rolled back to 4.19.0 as you suggested, and it works!
Thanks very much for the hint.
I will comment in the existing GitHub issue - I don’t thnk we need to make a new one.