This library provides support for native PostgreSQL enums in Liquibase. This library was designed to be used in conjunction with our liquibase-changelog-generator library such that in many cases the required changelogs are generated automatically. Furthermore, this library was designed such that it works with Hibernate’s support for native PostgreSQL enums that was introduced in Hibernate 6.2.
Add the following Maven runtime dependency to your project:
<dependency>
<groupId>de.cronn</groupId>
<artifactId>liquibase-postgres-enum-extension</artifactId>
<version>1.1</version>
<scope>runtime</scope>
</dependency>
For Hibernate entities, we recommend annotating attributes of enum type as shown below:
@JdbcType(PostgreSQLEnumJdbcType.class)
Status status;
The library provides additional liquibase commands, that can be used within a changeSet
:
<ext:createPostgresEnumType name="color" values="RED, GREEN, BLUE"/>
<ext:addPostgresEnumValues enumTypeName="color" valuesToAdd="BLACK, WHITE"/>
<ext:renamePostgresEnumValue enumTypeName="color" oldValue="BLACK" newValue="KEY"/>
PostgreSQL does not yet support removing of values of an existing enum. Instead, we implement a workaround by replacing the enum with a new enum type that has different values (as described in this blog post).
⚠ You need to be extra careful when you drop an enum value! First, you need to update the existing tables
to make sure that the value is not used anymore, typically using an UPDATE
statement.
<ext:modifyPostgresEnumType name="color" newValues="CYAN, MAGENTA, YELLOW, KEY"/>
<ext:renamePostgresEnumType oldName="color" newName="colour"/>
<ext:dropPostgresEnumType name="color"/>
- Java 17+
- Liquibase 4.27+