Skip to content
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

Migrations: Support ENUM field #8

Open
saada opened this issue Sep 29, 2015 · 29 comments
Open

Migrations: Support ENUM field #8

saada opened this issue Sep 29, 2015 · 29 comments
Labels

Comments

@saada
Copy link

saada commented Sep 29, 2015

ENUM("ONE", "TWO", "THREE") NOT NULL'

should be supported via

$this->enum(['ONE', 'TWO', 'THREE'])->notNull();

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@usualdesigner
Copy link

+1

1 similar comment
@wbraganca
Copy link

+1

@samdark
Copy link
Member

samdark commented Oct 2, 2015

Is enum supported by all DBs that are supported in Yii?

@nineinchnick
Copy link

@samdark even if not directly supported by a db, adding a check constraint to limit values makes it look like an enum:

ALTER TABLE table ADD CONSTRAINT enum_col CHECK (enum_col IN ('value1', 'value2'));

CHECK constraints should be supported by most dbs, even SQLite.

@nineinchnick
Copy link

The drawback is that such a CHECK constraint won't be detected as an enum when Yii loads the schema and populates \yii\db\Column::$enumValues.

@samdark
Copy link
Member

samdark commented Oct 4, 2015

So Gii won't be able to generate based on such checks. And since we don't have it in schema we won't be able to work with these in a good way...

@nineinchnick
Copy link

We could have only one supported syntax and detect it, like the example i've posted above. I've already done detecting literal values when parsing column defaults in #9773.

@nineinchnick
Copy link

I actually use such CHECK syntax often and would be interested if it gets detected, because now I have to add it in the model manually.

@saada
Copy link
Author

saada commented Mar 22, 2016

It would be great to have support for an API like

$this->addEnumValue($tableName, $columnName, ['NEW_ENUM_VALUE']);
$this->removeEnumValue($tableName, $columnName, ['NEW_ENUM_VALUE']);

@gitowiec
Copy link

gitowiec commented May 2, 2016

+1

@saada
Copy link
Author

saada commented May 2, 2016

The biggest challenge with adding/removing ENUM values from a column is migrating old records to the new values. Maybe that should be the responsibility of the developer to write the proper updateAll() statements in their migration?

@arren-ru
Copy link

arren-ru commented May 10, 2016

I assume that adding a default value can solve the problem with the data migration.
Another way is to migrate by adding a new values, doing some changes after that, and finally removing unnecessary values from enum.

@kiironoaki
Copy link

+1

2 similar comments
@dignityinside
Copy link

+1

@tommyknocker
Copy link

+1

@SilverFire
Copy link
Member

We are glad to accept a pull request with the suggested enhancement

@newerton
Copy link

+1

2 similar comments
@planet17
Copy link

planet17 commented Aug 8, 2017

+1

@paulocoutinhox
Copy link

+1

@harsiddhi
Copy link

how to add default value in enum ??

@cebe
Copy link
Member

cebe commented Aug 22, 2017

ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a'?

@designia
Copy link

+1

@santilin
Copy link

santilin commented Oct 5, 2017

Is anyone working on this?

@samdark
Copy link
Member

samdark commented Oct 5, 2017

No.

@NetLS2013
Copy link

@samdark is this done?

@samdark samdark transferred this issue from yiisoft/yii2 Jan 2, 2019
@samdark
Copy link
Member

samdark commented Jan 2, 2019

No.

@samdark samdark transferred this issue from yiisoft/db Apr 24, 2019
@tomaszkane
Copy link

I really want to have enum and set column type support :-)

@samdark samdark added the type:feature New feature label Feb 25, 2021
@Radon8472
Copy link

Is this feature still in progress?

@samdark
Copy link
Member

samdark commented Oct 14, 2022

It is on hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests