Skip to content

cronn/liquibase-postgres-enum-extension

Repository files navigation

CI Maven Central Apache 2.0 codecov Valid Gradle Wrapper

Liquibase Extension for native PostgreSQL enums

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.

Usage

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>

Hibernate

Users of Hibernate typically annotate the enum columns with

@JdbcType(PostgreSQLEnumJdbcType.class)
Status status;

where Status is an enum class.

Commands

Creating an enum type

<ext:createPostgresEnumType name="color" values="RED, GREEN, BLUE"/>

Adding one or more values to an existing enum type

<ext:addPostgresEnumValues enumTypeName="color" valuesToAdd="BLACK, WHITE"/>

Renaming an existing enum value

<ext:renamePostgresEnumValue enumTypeName="color" oldValue="BLACK" newValue="KEY"/>

Removing one or more values of an existing enum

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"/>

Renaming an existing enum type

<ext:renamePostgresEnumType oldName="color" newName="colour"/>

Dropping an existing enum type

<ext:dropPostgresEnumType name="color"/>

Requirements

  • Java 17+
  • Liquibase 4.27+

About

Liquibase Extension for native PostgreSQL enums

Resources

License

Stars

Watchers

Forks