Skip to content

Commit

Permalink
Fix update db charset
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 committed Jul 9, 2024
1 parent 8b9929a commit 4d08926
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/Database/migrations/2024_07_09_210356_update_db_charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
Expand All @@ -13,6 +14,21 @@
*/
public function up()
{
// Change the charset only for mysql
if (DB::getDriverName() !== 'mysql') {
return;
}

// Check the current charset
$connection = DB::connection()->getPdo();
$statement = $connection->query("SHOW VARIABLES LIKE 'character_set_connection'");
$result = $statement->fetch(PDO::FETCH_ASSOC);

if ($result['Value'] === 'utf8mb4') {
return;
}


$this->changeDatabaseCharacterSetAndCollation('utf8mb4', 'utf8mb4_unicode_ci', 191, function ($column) {
return $this->isStringTypeWithLength($column) && $column['type_brackets'] > 191;
});
Expand Down

0 comments on commit 4d08926

Please sign in to comment.