Normalize integer type widths in schema compare to avoid false MODIFY

This commit is contained in:
DevSoftTech Server 2026-03-04 00:48:52 +05:30
parent 2b7b45849f
commit fc6b878bb3

View File

@ -1105,8 +1105,7 @@ class Setup extends BaseController
private function columnSignature(array $col): string private function columnSignature(array $col): string
{ {
$type = strtolower(trim((string) ($col['Type'] ?? ''))); $type = $this->normalizeColumnTypeForCompare((string) ($col['Type'] ?? ''));
$type = preg_replace('/\s+/', ' ', $type) ?? $type;
$nullability = strtoupper(trim((string) ($col['Null'] ?? 'YES'))); $nullability = strtoupper(trim((string) ($col['Null'] ?? 'YES')));
$nullability = $nullability === 'NO' ? 'NO' : 'YES'; $nullability = $nullability === 'NO' ? 'NO' : 'YES';
@ -1131,6 +1130,23 @@ class Setup extends BaseController
]) ?: ''; ]) ?: '';
} }
private function normalizeColumnTypeForCompare(string $type): string
{
$type = strtolower(trim($type));
$type = preg_replace('/\s+/', ' ', $type) ?? $type;
if ($type === '') {
return '';
}
// MySQL/MariaDB may report integer display width differently: int vs int(11), int unsigned vs int(10) unsigned.
// Ignore only integer display width for comparison to avoid false-positive MODIFY statements.
$type = preg_replace('/\b(tinyint|smallint|mediumint|int|integer|bigint)\s*\(\s*\d+\s*\)/i', '$1', $type) ?? $type;
$type = preg_replace('/\s+/', ' ', $type) ?? $type;
return trim($type);
}
private function ensureCreateTableIfNotExists(string $sql): string private function ensureCreateTableIfNotExists(string $sql): string
{ {
$sql = trim($sql); $sql = trim($sql);