liquibase / liquibase-hibernate

Liquibase Hibernate Integration
Apache License 2.0
271 stars 160 forks source link

liquibase:generateChangeLog creates UUID properties as char(32) in changelog #705

Open ChexWarrior opened 4 months ago

ChexWarrior commented 4 months ago

Hello,

Been working to integrate Liquibase with a Springboot project and while I have been able to run the generateChangeLog command via maven successfully I've noticed that all UUID properties I have specified in my entity classes all get translated to char(36) columns in the outputted changelog.

Command: ./mvnw liquibase:generateChangeLog -Dliquibase.verbose=true

Some output from the above command makes me think it is able to recognize the uuid attributes as UUIDs but something is getting lost during the generation of the changelog:

...
[INFO] Found column entity_id uuid
...

Sample Entity Snippet:

...
  @NotNull
  @Column(name = "entity_id")
  protected UUID id;
...

Sample changeset in generated changelog:

...
<createTable tableName="collection_revision">
            ...
            <column name="entity_id" type="char(36)">
                <constraints nullable="false"/>
            </column>
...

Manually replacing char(36) with uuid in the changelog and running an update against the db actually does seem to work when updating the actual database but I'd like to avoid such a manual workaround if possible. Is there anything anyone can think of which could be causing this? I saw in another issue that liquibase giving the column char(36) means it couldn't determine the type of database I was using but besides adding the dialect argument to the url above I don't know what else would indicate this to liquibase.

Some details:

liquibase.properties file:

url=hibernate:spring:com.redacted.hidden?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
driver=liquibase.ext.hibernate.database.connection.HibernateDriver

Maven Plugin config:

            <plugin>
               <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>4.28.0</version>
                <configuration>
                    <propertyFile>liquibase.properties</propertyFile>
                    <outputChangeLogFile>src/main/resources/config/liquibase/master.xml</outputChangeLogFile>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate6</artifactId>
                        <version>4.28.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase</groupId>
                        <artifactId>liquibase-core</artifactId>
                        <version>4.28.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-validation</artifactId>
                        <version>3.3.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-jdbc</artifactId>
                        <version>3.3.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>3.3.1</version>
                    </dependency>
                </dependencies>
            </plugin>
ChexWarrior commented 4 months ago

Got debugging with the maven command to work and I can see that my database is null when Liquibase checks the database type as mentioned here: https://github.com/liquibase/liquibase-hibernate/issues/166#issuecomment-2048150924

Now to find out why that is...