1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Updated default encoding and added conversion migration.

Also updated how DB port is defined so that the DB_PORT
env var can be used or it can be take from the host name.

Fixes #405
This commit is contained in:
Dan Brown
2017-07-02 17:20:05 +01:00
parent 7293ad7b24
commit 005f0eb4fc
3 changed files with 61 additions and 3 deletions

View File

@ -0,0 +1,46 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateDbEncodingToUt8mb4 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$database = DB::getDatabaseName();
$tables = DB::select('SHOW TABLES');
$pdo = DB::getPdo();
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$pdo->exec('ALTER DATABASE '.$database.' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
$key = 'Tables_in_' . $database;
foreach ($tables as $table) {
$tableName = $table->$key;
$pdo->exec('ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$database = DB::getDatabaseName();
$tables = DB::select('SHOW TABLES');
$pdo = DB::getPdo();
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$pdo->exec('ALTER DATABASE '.$database.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$key = 'Tables_in_' . $database;
foreach ($tables as $table) {
$tableName = $table->$key;
$pdo->exec('ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci');
}
}
}