formatOptions($type, $column); $schema->addColumn($column['name'], $typeName, $options); if ($column['primary_key']) { $primaryKeyColumns[] = $column['name']; } } if ($primaryKeyColumns) { $schema->setPrimaryKey($primaryKeyColumns); } return $schema; } /** * Converts column options to a format supported by Doctrine\DBAL\Schema\Column */ protected function formatOptions($type, $options) { $result = MigrationColumnType::lengthToPrecisionAndScale($type, $options['length']); $result['unsigned'] = !!$options['unsigned']; $result['notnull'] = !$options['allow_null']; $result['autoincrement'] = !!$options['auto_increment']; $default = trim($options['default']); // Note - this code doesn't allow to set empty string as default. // But converting empty strings to NULLs is required for the further // work with Doctrine types. As an option - empty strings could be specified // as '' in the editor UI (table column editor). if ($result['notnull'] === false) { if (strtolower($default) === 'null') { $result['default'] = null; } elseif (preg_match('/^[\'"]null[\'"]$/i', $default)) { $result['default'] = 'null'; } else { $result['default'] = $default === '' ? null : $default; } } else { $result['default'] = $default === '' ? null : $default; } return $result; } }