Skip to content

feat(postgres): add native enum type support#2412

Open
ErfanMomeniii wants to merge 3 commits into
cakephp:0.xfrom
ErfanMomeniii:0.x
Open

feat(postgres): add native enum type support#2412
ErfanMomeniii wants to merge 3 commits into
cakephp:0.xfrom
ErfanMomeniii:0.x

Conversation

@ErfanMomeniii
Copy link
Copy Markdown

Adds native PostgreSQL enum type support to PostgresAdapter.

Problem

PostgreSQL requires a two-step process for enum columns — first CREATE TYPE ... AS ENUM (...), then referencing that type in column definitions. Phinx only supported MySQL's inline ENUM('a','b') syntax.

See: #2258

Solution

Handle the full enum lifecycle automatically with the naming convention {table}_{column} (e.g. orders_status) to prevent cross-table collisions.

Operation Behavior
createTable() Emits CREATE TYPE before CREATE TABLE
addColumn() Emits CREATE TYPE before ALTER TABLE
dropColumn() Drops the associated enum type after column removal
dropTable() Drops all associated enum types after table removal
getColumns() Round-trips enums back as PHINX_TYPE_ENUM with values from pg_enum

Usage

$this->table('orders')
      ->addColumn('status', 'enum', [
          'values'  => ['pending', 'shipped', 'delivered'],
          'default' => 'pending',
      ])
      ->create();

Rollbacks work automatically — dropping a column or table cleans up the associated PostgreSQL type.

Tests

10 new integration tests covering create, add, drop column, drop table, round-trip, cross-table isolation, and schema-qualified tables.

Fixes #2258

@ErfanMomeniii
Copy link
Copy Markdown
Author

Hi @dereuromark , could you please review it?

@dereuromark
Copy link
Copy Markdown
Member

@MasterOdin took over maintainance.

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.

2 participants