-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Deprecate support for enums #8401
Comments
Can we elaborate on what alternative to enum we are advocating and why this would be a step forward? I agree that this would unblock #6632, and it would make our PGSQL implementation a little more consistent, but I'm skeptical of other benefits, and "modernize" as a benefit is a bit of a truism. Using ClassName as a specific example ClassName = varchar + Index + A separate constraint EDIT: The most significant change that this would make is the data usage of each record, which on big tables can get significant. Which may end up pushing us in the direction of the other 2 solutions, although one good thing we could do is avoid including the ClassName field on tables that don't support multiple classes. And then there are some solutions which I think would be a backward step: ClassName in a separate table and ClassNameID in the parent table ClassName is an integer an the lists are maintained in PHP So, in my view, this is solely justified by #6632. |
Let's leave that as the sole justification for now then =) |
You can pry my Enums from my cold, dead hands!!! 😱 On a serious note, if it's holding up #6632 it sounds like a worthwhile sacrifice. Sam's I'm wondering if we want to keep some sort of |
Yes I think application level support would be a good thing to let people still use them without affecting the DB, it would also be extensible. Doctrine have some examples of how we could do this in core: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/cookbook/mysql-enums.html |
Yeah, my immediate thought when I saw this blocker in #6632 was I’m trying to think if there are any drawbacks to not having a list of available values when inspecting a column. I can’t really think of a use-case for that, so it’s probably not worth worrying about - perhaps if we implement database-level constraints you could grab them from there... |
My opinion is that we should remove native DB enum support but have an application layer support for them. That means we still retain the "Enum" DB Field type in the ORM we just don't construct an enum in the database. We can still define a list of allowed values for a field but we just don't store that list in the DB. In my view, one of the biggest drawbacks of Enums is that it causes data corruption on dev/build when the enum values are changed, which makes rolling back database changes a huge pain. Just as an aside, there are a lot of things blocking #6632 including:
|
If we do address this we should also look at #1387, which is to say, we want to ensure that constraints get re-written when allowed elements change, or remove it altogether. I have to say that removing all constraints from the database and just storing a varchar, relying on PHP to maintain data integrity feels like a step backwards:
|
I would suggest that we start by introducing a config option, eg. DBEnum.use_native_enum = true. If you set it to false then it will add a varchar + constraint to the database instead of an enum. This will let enthusiasts try this feature out before we take the step of deprecating the current implementation, which personally I would only do if we were pretty far down the track of implementing DBAL |
Just dropping back in to list another disadvantage of enums. When deploying changes to an existing SS4 site, the |
#6632 is not something we're planning on doing any more, so this has less drive than it had. I like @sminnee's last idea of allowing config based opt-in. I don't think there's been enough interest in this RFC since I opened it two years ago to pursue it any further, so I'm going to close it. Thanks to everyone for the input! |
Affected Version
Deprecate in 4.x and remove in 5.x
Description
Support in SilverStripe for enum DB fields is one of the main blockers for moving to use doctrine for example.
Some other reasons why we shouldn't use enums:
We use enums for some quite fundamental parts of the framework, e.g. the ClassName field. We can replace this with application level logic and constant values instead.
Pros
Modernize the framework a little moreCons
The text was updated successfully, but these errors were encountered: