Skip to content

Commit 6e45eba

Browse files
committed
Address a few TODOs
1 parent 0dcecd1 commit 6e45eba

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

src/Db/Adapter/MysqlAdapter.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,25 @@ public function getColumnTypes(): array
919919
return $types;
920920
}
921921

922+
/**
923+
* Get the default encoding for the current database.
924+
*
925+
* @return string The default encoding
926+
*/
927+
public function getDefaultCollation(): string
928+
{
929+
$encodingRequest = 'SELECT DEFAULT_COLLATION_NAME
930+
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = :dbname';
931+
932+
$connection = $this->getConnection();
933+
$connectionConfig = $connection->config();
934+
935+
$statement = $connection->execute($encodingRequest, ['dbname' => $connectionConfig['database']]);
936+
$row = $statement->fetch('assoc');
937+
938+
return $row['DEFAULT_COLLATION_NAME'] ?? '';
939+
}
940+
922941
/**
923942
* Whether the server has a native uuid type.
924943
* (MariaDB 10.7.0+)

src/Db/Table.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Migrations\Db\Action\RenameColumn;
2626
use Migrations\Db\Action\RenameTable;
2727
use Migrations\Db\Adapter\AdapterInterface;
28+
use Migrations\Db\Adapter\MysqlAdapter;
2829
use Migrations\Db\Plan\Intent;
2930
use Migrations\Db\Plan\Plan;
3031
use Migrations\Db\Table\Column;
@@ -637,19 +638,10 @@ public function create(): void
637638
}
638639

639640
$adapter = $this->getAdapter();
640-
if ($adapter->getAdapterType() === 'mysql' && empty($options['collation'])) {
641-
// TODO this should be a method on the MySQL adapter.
642-
// It could be a hook method on the adapter?
643-
$encodingRequest = 'SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
644-
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = :dbname';
645-
646-
$connection = $adapter->getConnection();
647-
$connectionConfig = $connection->config();
648-
649-
$statement = $connection->execute($encodingRequest, ['dbname' => $connectionConfig['database']]);
650-
$defaultEncoding = $statement->fetch('assoc');
651-
if (!empty($defaultEncoding['DEFAULT_COLLATION_NAME'])) {
652-
$options['collation'] = $defaultEncoding['DEFAULT_COLLATION_NAME'];
641+
if ($adapter instanceof MysqlAdapter && empty($options['collation'])) {
642+
$collation = $adapter->getDefaultCollation();
643+
if ($collation) {
644+
$options['collation'] = $collation;
653645
}
654646
}
655647

src/Util/Util.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ public static function getVersionFromFileName(string $fileName): int
114114
*/
115115
public static function mapClassNameToFileName(string $className): string
116116
{
117-
// TODO it would be nice to replace this with Inflector::underscore
118-
// but it will break compatibility for little end user gain.
119117
$snake = function ($matches) {
120118
return '_' . strtolower($matches[0]);
121119
};

src/View/Helper/MigrationHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,13 @@ public function getColumnOption(array $options): array
408408
}
409409

410410
if (($isMysql || $isSqlserver) && !empty($columnOptions['collate'])) {
411-
// TODO fix this when migrations is aligned with cakephp/database
411+
// TODO deprecate this in 5.x
412412
// Change keys due to Phinx using different naming for the collation
413413
$columnOptions['collation'] = $columnOptions['collate'];
414414
unset($columnOptions['collate']);
415415
}
416416

417+
// TODO deprecate precision/scale and align with cakephp/database in 5.x
417418
// TODO this can be cleaned up when we stop using phinx data structures for column definitions
418419
if (!isset($columnOptions['precision']) || $columnOptions['precision'] == null) {
419420
unset($columnOptions['precision']);

0 commit comments

Comments
 (0)