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>
Users of Hibernate typically annotate the enum columns with
@JdbcType(PostgreSQLEnumJdbcType.class)
Status status;
where Status
is an enum class.
<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 described in https://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/ by replacing the enum with a new enum type that has different values.
⚠ 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+