feat(postgres): add native enum type support#2412
Conversation
|
Hi @dereuromark , could you please review it? |
|
@MasterOdin took over maintainance. |
There was a problem hiding this comment.
Pull request overview
Adds native PostgreSQL enum support to Phinx by introducing a managed enum-type lifecycle in PostgresAdapter (create type before table/column creation, drop type on column/table removal) and round-tripping enums back to PHINX_TYPE_ENUM via catalog inspection.
Changes:
- Add
PHINX_TYPE_ENUMsupport toPostgresAdapter(DDL emission + column introspection for enum labels). - Update shared type constants/comments to reflect enum support beyond MySQL.
- Add Postgres integration tests covering enum create/add/drop and round-tripping behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/Phinx/Db/Adapter/PostgresAdapter.php |
Implements enum type creation, drop cleanup, and enum detection/round-trip in getColumns(). |
src/Phinx/Db/Table/Column.php |
Updates Column::ENUM documentation to reflect Postgres support. |
src/Phinx/Db/Adapter/AdapterInterface.php |
Reclassifies PHINX_TYPE_ENUM as supported by MySQL + PostgreSQL. |
tests/Phinx/Db/Adapter/PostgresAdapterTest.php |
Adds integration tests validating enum lifecycle and getColumns() round-tripping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ma-aware enum helpers
|
@MasterOdin are u ok with this? |
MasterOdin
left a comment
There was a problem hiding this comment.
I think there's a bug here where since using the table and column name to look up enum names, if a rename happens for either, then the link breaks on the enum. Probably should add a rename of the enum on renaming the table or column I guess? Alternative would be to do a DB look-up of the enum name when doing a drop column or drop table.
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 inlineENUM('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.createTable()CREATE TYPEbeforeCREATE TABLEaddColumn()CREATE TYPEbeforeALTER TABLEdropColumn()dropTable()getColumns()PHINX_TYPE_ENUMwith values frompg_enumUsage
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