-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Schema::TYPE_TEXT is too short in MySQL #2
Comments
I made a simple extension that does this: https://github.com/nkovacs/yii2-mysql |
why this important feature is in the 2.1 and not for the 2.0.9 ? :/ thx |
Because it probably breaks backwards compatibility, and such changes can only go into 2.1. |
oh well :/ for now only work adding directly i will wait 2.1.x |
Can be solved using |
Checked, if size is specified, type will be created depending on size. For example, use From the documentation: https://dev.mysql.com/doc/refman/8.4/en/string-type-syntax.html |
Tests and doc will be added |
Schema::TYPE_TEXT
converts to TEXT in MySQL. This is just 64K, which is not a lot. Unless it's in strict mode, MySQL will truncate anything longer when inserting, and not throw an error (it'll throw a warning, but you'll have to look in the mysql server log).You can use MEDIUMTEXT and LONGTEXT for your fields, but that only works in MySQL, and not in Postgre and Sqlite for example (where TEXT is long enough), so if you're writing portable code, you can't just use
'MEDIUMTEXT'
.It's also likely that most developers will just use Yii's schema types, without knowing that the data is limited to 64K.
I see several possible solutions to this:
\yii\db\mysql\QueryBuilder::$typeMap[Schema::TYPE_TEXT]
to'MEDIUMTEXT'
or'LONGTEXT'
. This adds 1 or 2 extra bytes per field per row, which can add up if you have a lot of rows, but in typical use cases shouldn't matter much. It's better to have a safe default, and let those who know the trade-offs optimize it. This change would cause inconsistency in existing databases (fields that were created before the change would remain TEXT, new ones would become MEDIUMTEXT, while rebuilding the database using the new version would create all MEDIUMTEXT).I'm going to change the default to MEDIUMTEXT for my projects, overwriting the typeMap in mysql\QueryBuilder. Unfortunately, the query builder is not created using Yii::createObject, so I can't use DI to do this, and I'll have to extend both \yii\db\mysql\Schema and \yii\db\mysql\QueryBuilder,
then overwrite the db connection's schemaMap (and I can't change just the mysql schema in the application configuration, I have to replace the whole thing). This is really inconvenient. Is there a better way to do this?I can use DI to replace the Schema at least.The text was updated successfully, but these errors were encountered: