Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5y3ArhRbakfu1ELsP
22 lines
1.4 KiB
Plaintext
22 lines
1.4 KiB
Plaintext
# PostgreSQL native enum (CREATE TYPE ... AS ENUM): ordering, ALTER TYPE, and what cannot be undone
|
|
# Hibernate ORM 7.4.17.Final, H2 2.4.240 and PostgreSQL 18.6, JDK 25
|
|
|
|
== Ordering. Enum declared as NEW, PAID, SHIPPED, CANCELLED (the order a workflow would use)
|
|
-- type created by Hibernate (hbm2ddl = create)
|
|
enum labels in sort order: [CANCELLED, NEW, PAID, SHIPPED]
|
|
order by status : [CANCELLED, NEW, PAID, SHIPPED]
|
|
-- type written by hand, labels in workflow order
|
|
order by status : [NEW, PAID, SHIPPED, CANCELLED]
|
|
|
|
== Release 2 needs CANCELLED, but the database type was created from release 1's NEW, PAID, SHIPPED
|
|
write CANCELLED before ALTER TYPE : org.hibernate.exception.DataException <- org.postgresql.util.PSQLException
|
|
ERROR: invalid input value for enum statusv1: "CANCELLED"
|
|
after ALTER TYPE statusv1 ADD VALUE 'CANCELLED' : OK, rows [1 | PAID, 10 | CANCELLED]
|
|
labels now (appended at the end): [NEW, PAID, SHIPPED, CANCELLED]
|
|
ADD VALUE 'ON_HOLD' BEFORE 'PAID' : labels [NEW, ON_HOLD, PAID, SHIPPED, CANCELLED]
|
|
RENAME VALUE 'PAID' TO 'PAYMENT_RECEIVED' : row 1 is now [PAYMENT_RECEIVED]
|
|
ALTER TYPE ... DROP VALUE : ERROR: dropping an enum value is not implemented
|
|
|
|
== ADD VALUE inside a transaction: usable only after commit
|
|
ADD VALUE then INSERT using it in ONE transaction : ERROR: unsafe use of new value "CANCELLED" of enum type statusv1
|