Skip to content

feat(schema): model enum renames and replace an enum on its name - #66

Merged
omer-cengel merged 1 commit into
masterfrom
feature/model-enum-renames
Oct 10, 2026
Merged

omer-cengel merged 1 commit into
masterfrom
feature/model-enum-renames

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

Migration histories that rename an enum type, rename an enum label, or replace an enum by declaring a new type under its name now load. Previously every ALTER TYPE action other than ADD VALUE was rejected, and a CREATE TYPE onto an existing enum name failed as Type already exists, so the common replace-an-enum migration could not be read.

Changes

  • ALTER TYPE ... RENAME TO renames a modeled enum in its position, keeping its labels; every column of that type, scalar and array alike, follows the new name.
  • ALTER TYPE ... RENAME VALUE renames a label in its position, preserving PostgreSQL's sort order; a missing label or an existing new label fails as PostgreSQL rejects it.
  • A CREATE TYPE ... AS ENUM or RENAME TO onto a modeled enum's name replaces that enum in its position, because the DROP TYPE that freed the name is not readable. Both usual migration shapes load: renaming the old type away first, or declaring the new type beside it and renaming it onto the old name.
  • OWNER TO and the composite attribute actions are ignored without resolving the type. RENAME TO and SET SCHEMA of a type sqlcj does not model are ignored.
  • SET SCHEMA of a modeled enum is rejected as Unsupported ALTER TYPE action: SET SCHEMA <schema> at line <n>.
  • Schema-parser tests cover each action and both replacement variants. A PostgreSQL integration test applies a replacement migration and runs generated code over the replaced enum and enum-array columns.
  • The PostgreSQL guide documents each ALTER TYPE form, the replacement rule, and the remaining diagnostics.

Scope and non-goals

  • Type names are still the statement's literal name with delimiters removed, so public.mood and mood are different names. A qualified RENAME TO or SET SCHEMA name that matches no modeled enum fails as Type not found rather than being ignored.
  • A qualified RENAME TO target, several comma-joined actions, and SET (...) stay rejected as unreadable type DDL.
  • DROP TYPE is still ignored. A column that still names a replaced enum is modeled with the replacing enum's labels, the same unseen DROP TYPE ... CASCADE case already documented.
  • Composite types are not modeled.

ALTER TYPE ... RENAME TO renames a modeled enum in its position and every
scalar and array column of that type follows it; RENAME VALUE renames a
label in its position. A CREATE TYPE ... AS ENUM or RENAME TO onto a
modeled enum's name replaces that enum, so the migration that replaces an
enum loads in either usual shape. OWNER TO and the attribute actions are
ignored without resolving the type, RENAME TO and SET SCHEMA of an
unmodeled type are ignored, and SET SCHEMA of a modeled enum is rejected
naming the action.
@omer-cengel
omer-cengel merged commit 6034302 into master Oct 10, 2026
7 checks passed
@omer-cengel
omer-cengel deleted the feature/model-enum-renames branch October 10, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant