Skip to content

Commit

Permalink
Convert columns for emoji support (#169)
Browse files Browse the repository at this point in the history
* removed some links from migration

* Fix StyleCI

* Move file

* Remove old tables

* Remove unneeded migrations

* Fix StyleCI

* Simplify script

* Fix psalm

* Fix StyleCI
  • Loading branch information
adrum authored and asbiin committed May 25, 2018
1 parent 0bee03a commit 643efa1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
16 changes: 8 additions & 8 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => env('DB_PREFIX', ''),
'strict' => false,
'engine' => null,
Expand All @@ -74,8 +74,8 @@
'database' => env('DB_TEST_DATABASE'),
'username' => env('DB_TEST_USERNAME'),
'password' => env('DB_TEST_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
],
Expand All @@ -87,8 +87,8 @@
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => env('DB_PREFIX', ''),
'charset' => 'utf8',
'schema' => 'public',
],

Expand All @@ -100,7 +100,6 @@
'username' => env('DB_TEST_USERNAME'),
'password' => env('DB_TEST_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'schema' => 'public',
],
Expand Down Expand Up @@ -160,8 +159,9 @@
'database' => starts_with($url['path'], '/') ? str_after($url['path'], '/') : $url['path'],
'username' => $url['user'],
'password' => $url['pass'],
'charset' => 'utf8',
'prefix' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => env('DB_PREFIX', ''),
'strict' => false,
'schema' => 'public',
];
Expand Down
37 changes: 37 additions & 0 deletions database/migrations/2018_05_24_203000_convert_mysql_encoding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

class ConvertMysqlEncoding extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$connection = DB::connection();

if ($connection->getDriverName() == 'mysql') {
$databasename = $connection->getDatabaseName();

// Tables
$tables = $connection->table('information_schema.tables')
->select('table_name')
->where('table_schema', '=', $databasename)
->get();

foreach ($tables as $table) {
DB::statement('ALTER TABLE `'.$table->table_name.'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;');
}

// Database
$pdo = $connection->getPdo();
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
DB::statement('ALTER DATABASE `'.$databasename.'` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
}
}

0 comments on commit 643efa1

Please sign in to comment.