Skip to content

Commit

Permalink
Fix integer column limit
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Sep 22, 2023
1 parent 0cb0dd5 commit f125b82
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Migration/Adapter/Generator/PhinxMySqlColumnOptionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ private function getPhinxColumnOptionsTimestamp(array $attributes, array $column
private function getPhinxColumnOptionsLimit(array $attributes, array $columnData): array
{
$limit = $this->getColumnLimit($columnData);
if ($limit) {
$attributes['limit'] = new RawPhpValue($limit);
if ($limit !== null) {
$attributes['limit'] = $limit;
}

return $attributes;
Expand All @@ -220,11 +220,10 @@ private function getPhinxColumnOptionsLimit(array $attributes, array $columnData
*
* @param array $columnData
*
* @return string
* @return int|RawPhpValue|null The limit
*/
private function getColumnLimit(array $columnData): string
private function getColumnLimit(array $columnData): RawPhpValue|int|null
{
$limit = '0';
$type = $this->getMySQLColumnType($columnData);

$mappings = [
Expand All @@ -245,14 +244,18 @@ private function getColumnLimit(array $columnData): string
$adapterConst = $mappings[$type] ?? null;

if ($adapterConst) {
$limit = $adapterConst;
} elseif (!empty($columnData['CHARACTER_MAXIMUM_LENGTH'])) {
$limit = $columnData['CHARACTER_MAXIMUM_LENGTH'];
} elseif (preg_match('/\((\d+)\)/', $columnData['COLUMN_TYPE'], $match) === 1) {
$limit = $match[1];
return new RawPhpValue($adapterConst);
}

return $limit;
if (!empty($columnData['CHARACTER_MAXIMUM_LENGTH'])) {
return (int)$columnData['CHARACTER_MAXIMUM_LENGTH'];
}

if (preg_match('/\((\d+)\)/', $columnData['COLUMN_TYPE'], $match) === 1) {
return (int)$match[1];
}

return null;
}

/**
Expand All @@ -277,7 +280,7 @@ private function getPhinxColumnOptionsNumeric(array $attributes, array $columnDa
$match = null;
if (preg_match('/\((\d+)\)/', $columnData['COLUMN_TYPE'], $match) === 1) {
if ($match[1] !== $intDefaultLimits[$dataType]) {
$attributes['limit'] = $match[1];
$attributes['limit'] = (int)$match[1];
}
}

Expand Down

0 comments on commit f125b82

Please sign in to comment.