public function migrateSyntaxFieldCreate($fieldName, array $fieldInfo)
{
// Get adapter options and type from typeHandler
$typeHandler = Config::typeHandler($fieldInfo['type']);
$fieldInfo = array_merge($fieldInfo, $typeHandler::adapterOptions());
$adapterType = $this->_fieldTypeMap[$fieldInfo['type']]['adapter_type'];
$syntax = "`" . $fieldName . "` " . $adapterType;
// Column type and length
$syntax .= $fieldInfo['length'] ? '(' . $fieldInfo['length'] . ')' : '';
// Unsigned
$syntax .= $fieldInfo['unsigned'] ? ' unsigned' : '';
// Collate
$syntax .= $fieldInfo['type'] == 'string' || $fieldInfo['type'] == 'text' ? ' COLLATE ' . $this->_collate : '';
// Nullable
$isNullable = true;
if ($fieldInfo['required'] || !$fieldInfo['null']) {
$syntax .= ' NOT NULL';
$isNullable = false;
}
// Default value
if ($fieldInfo['default'] === null && $isNullable) {
$syntax .= " DEFAULT NULL";
} elseif ($fieldInfo['default'] !== null) {
$default = $fieldInfo['default'];
// If it's a boolean and $default is boolean then it should be 1 or 0
if (is_bool($default) && $fieldInfo['type'] == "boolean") {
$default = $default ? 1 : 0;
}
if (is_scalar($default)) {
$syntax .= " DEFAULT '" . $default . "'";
}
}
// Extra
$syntax .= $fieldInfo['primary'] && $fieldInfo['serial'] ? ' AUTO_INCREMENT' : '';
return $syntax;
}