Skip to content

Comments

Add native enumerated column types#99

Open
mringler wants to merge 3 commits intodevelopfrom
enum_fixup
Open

Add native enumerated column types#99
mringler wants to merge 3 commits intodevelopfrom
enum_fixup

Conversation

@mringler
Copy link
Collaborator

Introduces column types ENUM_NATIVE and SET_NATIVE, which map to the MySQL ENUM and SET type.

Old Propel ENUM and SET types are now aliases for the new ENUM_BINARY and SET_BINARY types. This mapping can be changed in perpl configuration file by setting the generator.defaultToNativeEnumeratedColumnTypes to true.

On platforms that have no native ENUM/SET type (all but MySQL), the *_NATIVE type resolves to the *_BINARY type.

ENUM_NATIVE is just a regular string column on PHP side, while SET_NATIVE columns handles transformation between string representation in DB and array representation in PHP.

see discussion in #97

@oojacoboo
Copy link

oojacoboo commented Feb 11, 2026

On platforms that have no native ENUM/SET type (all but MySQL)

Not sure the full list of RDBMS that Perpl supports, but Postgres definitely supports enums as well.

Also, can you provide some example configs for enums?

I see this in the tests:

<database>
    <table name="migration_test_enum">
        <column name="enum_column" type="ENUM_NATIVE" valueSet="baz,foo,bar"/>
        <column name="set_column" type="SET_NATIVE" valueSet="baz,foo,bar"/>
    </table>
</database>

I'm a little confused on what the purpose of SET_NATIVE is versus ENUM_NATIVE.

Also, I wanted to check that phpType property is supported to assign an existing enum to be used for the column/type.

@mringler
Copy link
Collaborator Author

I also thought ENUM is a quite common concept, turns out it's pretty much MySQL-specific. Postgres is the only other DBMS that comes close, but it requires enums to be defined as types, which then can be used as column type:

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

(from docs)

Not sure if it makes sense to add this.

I'm a little confused on what the purpose of SET_NATIVE is versus ENUM_NATIVE.

I used to get SET and ENUM confused all the time. No more after this.
SET allows to assign multiple values, while ENUM is single value only. So SET_NATIVE will contain an array, but ENUM_NATIVE is just a string.

Also, I wanted to check that phpType property is supported to assign an existing enum to be used for the column/type.

Yes, this is still missing.

@oojacoboo
Copy link

Postgres had enums before MySQL did. It's a far more advanced database. But yes, you need to create them by adding a type, which is a proper way of doing it, since an enum can be used across multiple tables. I'm not sure how MySQL implemented them recently. I'd hope they have something similar to creating a type.

Regarding SET, that's not really an enum to me. A column that's storing multiple "enum" values, isn't really a proper enum column. You don't get database level constraints on this type of design. I guess you could add "checks" in Postgres to help out. Anyway, IMO that shouldn't even be supported. But I guess it's already there.

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