cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.45k stars 895 forks source link

Support enums in postgres #2258

Open rbalik opened 7 months ago

rbalik commented 7 months ago

Hi there, basically just checking to see if this something you all would consider adding. Postgres supports enums on columns but it's a two-step process where you make an enum type and then you set that type on the create like this:

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
    name text,
    current_mood mood
);

More information at https://www.postgresql.org/docs/current/datatype-enum.html

dereuromark commented 7 months ago

So far CakePHP has never used enums as such, as they have a lot of disadvantages. Instead tinyint(2) and a PHP internal mapping has been used to better handle this kind of use case.

But that said a PR for such a feature is welcome. Folks outside of CakePHP or in general interested in using this feature despite the disadvantages sure could find it useful.

LordSimal commented 7 months ago

The problem with PostgreSQL enums is the fact, that (only in PostgreSQL) they are sort of a custom column type instead of a generic enum column type (like in MySQL 8) which has additional data inside it.

rbalik commented 7 months ago

Right yeah, I showed that in my example. It's definitely more annoying to deal with so I understand if lower down the list. Figured I'd check what you all were thinking though.

dereuromark commented 7 months ago

Like I said: it would have to be a community PR As seen from other tickets: there is no big incentive for those topics to be addressed from maintainer side. Best to do it yourself if u are interested in this feature

rbalik commented 7 months ago

Got it. Thanks