On Friday, November 30, 2012 1:24:42 AM UTC-8, John Anderson wrote:
>
> With a mysql-5.5 server using charset utf8mb4 (supports 4 byte utf8
> characters), doing this
>
> mysql --default-character-set=utf8mb4 -uroot -ppassword db_name
>
> mysql> CREATE TABLE `schema_migrations` (`filename` varchar(255) PRIMARY
> KEY);
>
> fails because mysql with myisam has a 1000 byte limit on index fields,
> and innodb has a 767 byte limit on index fields.
>
> mysql> SET storage_engine=innodb;
> mysql> CREATE TABLE `schema_migrations` (`filename` varchar(255) PRIMARY
> KEY);
> ERROR 1071 (42000): Specified key was too long; max key length is 767
> bytes
>
> mysql> SET storage_engine=MYISAM;
> mysql> CREATE TABLE `schema_migrations` (`filename` varchar(255) PRIMARY
> KEY);
> ERROR 1071 (42000): Specified key was too long; max key length is 1000
> bytes
>
> The type_literal_generic_string method assumes (reasonably, IMHO) that a
> String field with no length specified should have a length of 255. And
> the schema_dataset method for datestamp migrations does not provide a
> limit when it creates the schema_migrations table.
>
> I've worked around this for my case. But it will impact anyone using
> migrations to create a String field with no length specified, with mysql
> and utf8mb4.
>
> I'm happy to provide a patch, but I'm not sure of the best place to
> figure out the maximum length for String fields. The adapter maybe?
>
The following monkey patch should work around the issue for MySQL databases
using utf8mb4 as the default character set:
def DB.type_literal_generic_string(column)
column[:size] ? super : super(column.merge(:size=>191))
end
Fixing this automatically at the MySQL shared adapter level is possible
after some small refactoring, but it would require code to check the
default character set upon database initialization. I don't really like
that approach, but I would be amenable to supporting a database option for
the default string column length:
DB = Sequel.connect('mysql://host/db?default_string_column_length=191')
This approach is more general and could be used for other purposes, but it
does require users of the MySQL utf8mb4 default character set to manually.
I'll go ahead and make that change now, since any other change would likely
depend on that support.
If Sequel/MySQL users think this is something that Sequel should
auto-detect and handle automatically, I'm OK with doing so if the community
is strongly in favor. So if you have strong feelings about this one way or
the other, please speak up.
Or maybe just limit the schema_migrations.filename field to 191 characters?
>
We can't do that as it has the potential to break existing installations
(which could have migration filenames longer than 191 characters).
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/O33ts3rb1WkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.