mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Shorten default string length
- Introduce varcharmax config item, this default eventually should be increased to 255, when MySQL 5.6 support is dropped - Config item can be kept to retain legacy support - Only apply to mysql driver, previously was impacting other drivers - Source true config values, previously was sourcing hard coded "mysql" connection values
This commit is contained in:
parent
bbed527ecc
commit
160ae441ff
@ -53,16 +53,17 @@ return [
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'engine' => 'InnoDB',
|
||||
'host' => 'localhost',
|
||||
'port' => 3306,
|
||||
'database' => 'database',
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'driver' => 'mysql',
|
||||
'engine' => 'InnoDB',
|
||||
'host' => 'localhost',
|
||||
'port' => 3306,
|
||||
'database' => 'database',
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'varcharmax' => 191,
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace System;
|
||||
|
||||
use Db;
|
||||
use App;
|
||||
use View;
|
||||
use Event;
|
||||
@ -84,9 +85,7 @@ class ServiceProvider extends ModuleServiceProvider
|
||||
public function boot()
|
||||
{
|
||||
// Fix UTF8MB4 support for MariaDB < 10.2 and MySQL < 5.7
|
||||
if (Config::get('database.connections.mysql.charset') === 'utf8mb4') {
|
||||
Schema::defaultStringLength(191);
|
||||
}
|
||||
$this->applyDatabaseDefaultStringLength();
|
||||
|
||||
// Fix use of Storage::url() for local disks that haven't been configured correctly
|
||||
foreach (Config::get('filesystems.disks') as $key => $config) {
|
||||
@ -564,4 +563,24 @@ class ServiceProvider extends ModuleServiceProvider
|
||||
{
|
||||
View::share('appName', Config::get('app.name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix UTF8MB4 support for old versions of MariaDB (<10.2) and MySQL (<5.7)
|
||||
*/
|
||||
protected function applyDatabaseDefaultStringLength()
|
||||
{
|
||||
if (Db::getDriverName() !== 'mysql') {
|
||||
return;
|
||||
}
|
||||
|
||||
$defaultStrLen = Db::getConfig('varcharmax', null);
|
||||
|
||||
if ($defaultStrLen === null && Db::getConfig('charset') === 'utf8mb4') {
|
||||
$defaultStrLen = 191;
|
||||
}
|
||||
|
||||
if ($defaultStrLen !== null) {
|
||||
Schema::defaultStringLength((int) $defaultStrLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user