-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
77 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,8 +135,8 @@ jobs: | |
MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }} | ||
run: | | ||
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi | ||
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_DSN='mysql://root:[email protected]/cakephp_test?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'; fi | ||
if [[ ${{ matrix.db-type }} == 'mysql:5.7' ]]; then export DB_DSN='mysql://root:[email protected]/cakephp_test?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'; fi | ||
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_DSN='mysql://root:[email protected]/cakephp_test?encoding=utf8mb4&init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'; fi | ||
if [[ ${{ matrix.db-type }} == 'mysql:5.7' ]]; then export DB_DSN='mysql://root:[email protected]/cakephp_test?encoding=utf8mb4&init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'; fi | ||
if [[ ${{ matrix.coverage }} == 'coverage' ]]; then | ||
export CODECOVERAGE=1 && vendor/bin/phpunit --stderr --verbose --coverage-clover=coverage.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
config/Migrations/20220209074122_AlterCharsetToUtf8mb4.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/* | ||
* Copyright 2022 ELASTIC Consultants Inc. | ||
*/ | ||
|
||
use Cake\Utility\Hash; | ||
use Migrations\AbstractMigration; | ||
|
||
/** | ||
* 20220209074122 テーブル、カラムの文字コードをutf8mb4に変更する | ||
* | ||
* @codingStandardsIgnoreStart | ||
*/ | ||
class AlterCharsetToUtf8mb4 extends AbstractMigration//@codingStandardsIgnoreEnd | ||
{ | ||
/** | ||
* Up Method. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
$query = $this->getQueryBuilder(); | ||
$schemaCollection = $query->getConnection()->getSchemaCollection(); | ||
if ($schemaCollection === null) { | ||
throw new Exception('$schemaCollection not exists.'); | ||
} | ||
|
||
$this->execute('SET FOREIGN_KEY_CHECKS=0;'); | ||
|
||
$tableNames = $schemaCollection->listTables(); | ||
$tableNames = array_filter($tableNames, static function ($tableName) { | ||
return in_array($tableName, ['activity_logs'], true) | ||
&& !preg_match('/_phinxlog$/', $tableName); | ||
}); | ||
foreach ($tableNames as $tableName) { | ||
// テーブルの文字照合順変更 | ||
$tableSchema = $schemaCollection->describe($tableName); | ||
$tableCollation = Hash::get($tableSchema->getOptions(), 'collation', ''); | ||
if (preg_match('/\Autf8_/', $tableCollation)) { | ||
$this->execute(sprintf('ALTER TABLE `%s` CHARACTER SET %s COLLATE %s', $tableName, 'utf8mb4', 'utf8mb4_general_ci')); | ||
} | ||
|
||
// カラムの文字照合順序変更 | ||
$table = $this->table($tableName); | ||
$colNames = $tableSchema->columns(); | ||
foreach ($colNames as $colName) { | ||
$column = $tableSchema->getColumn($colName); | ||
$columnCollation = Hash::get($column, 'collate', ''); | ||
if (preg_match('/\Autf8_/', $columnCollation)) { | ||
$colType = $column['type']; | ||
$colOpts = $column; | ||
unset($colOpts['type'], $colOpts['collate'], $colOpts['fixed']); | ||
$table->changeColumn($colName, $colType, ['collation' => 'utf8mb4_general_ci', 'encoding' => 'utf8mb4'] + $colOpts); | ||
} | ||
} | ||
$table->update(); | ||
} | ||
|
||
$this->execute('SET FOREIGN_KEY_CHECKS=1;'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters