db-migration
db-migration copied to clipboard
Migrations: Support ENUM field
ENUM("ONE", "TWO", "THREE") NOT NULL'
should be supported via
$this->enum(['ONE', 'TWO', 'THREE'])->notNull();
+1
+1
Is enum supported by all DBs that are supported in Yii?
@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.
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.
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...
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.
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.
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']);
+1
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?
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.
+1
+1
+1
We are glad to accept a pull request with the suggested enhancement
+1
+1
+1
how to add default value in enum ??
ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a'?
+1
Is anyone working on this?
No.
@samdark is this done?
No.
I really want to have enum and set column type support :-)
Is this feature still in progress?
It is on hold.