silverstripe / silverstripe-redirectedurls

Silverstripe module to let users to configure arbitrary redirections in the CMS
BSD 3-Clause "New" or "Revised" License
32 stars 48 forks source link

MySQL Index issue for utf8mb4 #63

Open selay opened 6 years ago

selay commented 6 years ago

The module breaks Silverstripe 4+ site if you are using utf8mb4 unicode which requires full 4 bytes. Although not tested (I simply removed this module and can have a look later), I guess the issue is caused by

 private static $indexes = array(
        'From' => array(
            'type' => 'unique',
            'columns' => array(
                'FromBase',
                'FromQuerystring',
            ),
        ),
    );

as it uses combined indexing.

The reason why it is a bug because Silverstripe itself supports full 4 bytes, and ideally the module would at least support the same requirements. SiteTree also uses Varchar(255) for URLSegment but that is fine.

Errors:

Couldn't run query:\n\nALTER TABLE \"RedirectedURL\" CHANGE \"ClassName\" \"ClassName\" enum('SilverStripe\\\\RedirectedURLs\\\\Model\\\\RedirectedURL') character set utf8mb4 collate utf8mb4_unicode_ci default 'SilverStripe\\\\RedirectedURLs\\\\Model\\\\RedirectedURL',\nCHANGE \"FromBase\" \"FromBase\" varchar(255) character set utf8mb4 collate utf8mb4_unicode_ci,\nCHANGE \"FromQuerystring\" \"FromQuerystring\" varchar(255) character set utf8mb4 collate utf8mb4_unicode_ci,\nCHANGE \"To\" \"To\" varchar(255) character set utf8mb4 collate utf8mb4_unicode_ci\n\n42000-1071: Specified key was too long; max key length is 767 bytes at ...\\vendor\\silverstripe\\framework\\src\\ORM\\Connect\\DBConnector.php:64)"} []

To replicate the issue, place this in your app.yml or mysite.yml and run dev build

  SilverStripe\ORM\Connect\MySQLDatabase:
    connection_charset: utf8mb4
    connection_collation: utf8mb4_unicode_ci
    charset: utf8mb4
    collation: utf8mb4_unicode_ci
Rhym commented 5 years ago

I came across this today, and fixed it with the following yml config:

---
name: utf8mb4_sizing
---
SilverStripe\RedirectedURLs\Model\RedirectedURL:
  db:
    FromBase: 'Varchar(150)'
    FromQuerystring: 'Varchar(100)'

Hope this helps anyone Googling the issue.