Skip to content

Commit

Permalink
Check for uuid support in getSqlType as well
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosp committed Dec 10, 2024
1 parent dd4288b commit 781387c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,11 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array
case static::PHINX_TYPE_UUID:
return ['name' => 'char', 'limit' => 36];
case static::PHINX_TYPE_NATIVEUUID:
if (!$this->hasNativeUuid()) {
throw new UnsupportedColumnTypeException(
'Column type "' . $type . '" is not supported by this version of MySQL.'
);
}
return ['name' => 'uuid'];

Check failure on line 1070 in src/Db/Adapter/MysqlAdapter.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Missing blank line before return statement

Check warning on line 1070 in src/Db/Adapter/MysqlAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Adapter/MysqlAdapter.php#L1070

Added line #L1070 was not covered by tests
case static::PHINX_TYPE_YEAR:
if (!$limit || in_array($limit, [2, 4])) {
Expand Down Expand Up @@ -1493,15 +1498,25 @@ public function describeTable(string $tableName): array
*/
public function getColumnTypes(): array
{
$connection = $this->getConnection();
$version = $connection->getDriver()->version();

$types = array_merge(parent::getColumnTypes(), static::$specificColumnTypes);

if (version_compare($version, '10.7', '>=')) {
if ($this->hasNativeUuid()) {
$types[] = self::PHINX_TYPE_NATIVEUUID;

Check warning on line 1504 in src/Db/Adapter/MysqlAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Adapter/MysqlAdapter.php#L1504

Added line #L1504 was not covered by tests
}

return $types;
}

/**
* Whether the server has a native uuid type.
* (MariaDB 10.7.0+)
* @return bool

Check failure on line 1513 in src/Db/Adapter/MysqlAdapter.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Expected 1 line between description and annotations, found 0.
*/
protected function hasNativeUuid(): bool
{
$connection = $this->getConnection();
$version = $connection->getDriver()->version();

return version_compare($version, '10.7', '>=');
}
}

0 comments on commit 781387c

Please sign in to comment.