Reduce unnecessary ALTER MODIFY by normalizing column signature
This commit is contained in:
parent
d4c16bd161
commit
2b7b45849f
|
|
@ -1105,12 +1105,29 @@ class Setup extends BaseController
|
||||||
|
|
||||||
private function columnSignature(array $col): string
|
private function columnSignature(array $col): string
|
||||||
{
|
{
|
||||||
|
$type = strtolower(trim((string) ($col['Type'] ?? '')));
|
||||||
|
$type = preg_replace('/\s+/', ' ', $type) ?? $type;
|
||||||
|
|
||||||
|
$nullability = strtoupper(trim((string) ($col['Null'] ?? 'YES')));
|
||||||
|
$nullability = $nullability === 'NO' ? 'NO' : 'YES';
|
||||||
|
|
||||||
|
$default = $col['Default'] ?? null;
|
||||||
|
if ($default === null) {
|
||||||
|
$defaultNormalized = '__NULL__';
|
||||||
|
} else {
|
||||||
|
$defaultStr = trim((string) $default);
|
||||||
|
$upper = strtoupper($defaultStr);
|
||||||
|
if ($upper === 'CURRENT_TIMESTAMP' || str_starts_with($upper, 'CURRENT_TIMESTAMP(')) {
|
||||||
|
$defaultNormalized = $upper;
|
||||||
|
} else {
|
||||||
|
$defaultNormalized = $defaultStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return json_encode([
|
return json_encode([
|
||||||
strtolower((string) ($col['Type'] ?? '')),
|
$type,
|
||||||
strtoupper((string) ($col['Null'] ?? 'YES')),
|
$nullability,
|
||||||
(string) ($col['Default'] ?? ''),
|
$defaultNormalized,
|
||||||
strtolower((string) ($col['Extra'] ?? '')),
|
|
||||||
(string) ($col['Comment'] ?? ''),
|
|
||||||
]) ?: '';
|
]) ?: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user