public function diffColumn(Column $column1, Column $column2) { $changedProperties = array(); if ($column1->getType() != $column2->getType()) { //espo: fix problem with executing query for custom types $column1DbTypeName = method_exists($column1->getType(), 'getDbTypeName') ? $column1->getType()->getDbTypeName() : $column1->getType()->getName(); $column2DbTypeName = method_exists($column2->getType(), 'getDbTypeName') ? $column2->getType()->getDbTypeName() : $column2->getType()->getName(); if (strtolower($column1DbTypeName) != strtolower($column2DbTypeName)) { $changedProperties[] = 'type'; } //END: espo } if ($column1->getNotnull() != $column2->getNotnull()) { $changedProperties[] = 'notnull'; } if ($column1->getDefault() != $column2->getDefault()) { $changedProperties[] = 'default'; } if ($column1->getUnsigned() != $column2->getUnsigned()) { $changedProperties[] = 'unsigned'; } if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) { // check if value of length is set at all, default value assumed otherwise. $length1 = $column1->getLength() ?: 255; $length2 = $column2->getLength() ?: 255; if ($length1 != $length2) { $changedProperties[] = 'length'; } if ($column1->getFixed() != $column2->getFixed()) { $changedProperties[] = 'fixed'; } } if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) { if (($column1->getPrecision() ?: 10) != ($column2->getPrecision() ?: 10)) { $changedProperties[] = 'precision'; } if ($column1->getScale() != $column2->getScale()) { $changedProperties[] = 'scale'; } } if ($column1->getAutoincrement() != $column2->getAutoincrement()) { $changedProperties[] = 'autoincrement'; } // only allow to delete comment if its set to '' not to null. if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) { $changedProperties[] = 'comment'; } $options1 = $column1->getCustomSchemaOptions(); $options2 = $column2->getCustomSchemaOptions(); $commonKeys = array_keys(array_intersect_key($options1, $options2)); foreach ($commonKeys as $key) { if ($options1[$key] !== $options2[$key]) { $changedProperties[] = $key; } } $diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1)); $changedProperties = array_merge($changedProperties, $diffKeys); return $changedProperties; }
public function getSql(Column $column, $table) { if (!$table instanceof Table) { $table = new Identifier($table); } $sql = array(); $normalized = $column->getType()->getNormalizedPostGISColumnOptions($column->getCustomSchemaOptions()); $srid = $normalized['srid']; // PostGIS 1.5 uses -1 for undefined SRID's if ($srid <= 0) { $srid = -1; } $type = strtoupper($normalized['geometry_type']); if ('ZM' === substr($type, -2)) { $dimension = 4; $type = substr($type, 0, -2); } elseif ('M' === substr($type, -1)) { $dimension = 3; } elseif ('Z' === substr($type, -1)) { $dimension = 3; $type = substr($type, 0, -1); } else { $dimension = 2; } // Geometry columns are created by the AddGeometryColumn stored procedure $sql[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $table->getName(), $column->getName(), $srid, $type, $dimension); if ($column->getNotnull()) { // Add a NOT NULL constraint to the field $sql[] = sprintf('ALTER TABLE %s ALTER %s SET NOT NULL', $table->getQuotedName($this->platform), $column->getQuotedName($this->platform)); } return $sql; }
public function __construct(TableInformation $parent, \Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) { $this->table = $parent; foreach ($table->getForeignKeys() as $foreign) { if (in_array($column->getName(), $foreign->getColumns())) { $foreign_columns = $foreign->getForeignColumns(); $this->foreignTable = $foreign->getForeignTableName(); $this->foreignColumn = reset($foreign_columns); $this->isForeign = true; } } if ($primary_key = $table->getPrimaryKey()) { $this->isPrimary = in_array($column->getName(), $primary_key->getColumns()); } $this->name = $column->getName(); $this->type = $column->getType()->getName(); $this->length = $column->getLength(); $this->precision = $column->getPrecision(); $this->default = $column->getDefault(); $this->isNotNull = $column->getNotnull(); $this->isUnsigned = $column->getUnsigned(); $this->isFixed = $column->getFixed(); $this->isAutoIncrement = $column->getAutoincrement(); $this->comment = $column->getComment(); if ($this->type === \Doctrine\DBAL\Types\Type::BLOB) { $this->length = min($this->bytesFromIni('post_max_size'), $this->bytesFromIni('upload_max_filesize')); } }
/** * Creates a column replacement, which has a quoted name. * * @param Column $column * * @return Column */ private function createColumnReplacement(Column $column) { $columnConfig = $column->toArray(); $columnConfig['platformOptions'] = $column->getPlatformOptions(); $columnConfig['customSchemaOptions'] = $column->getCustomSchemaOptions(); return new Column($this->platform->quoteIdentifier($column->getName()), $column->getType(), $columnConfig); }
protected function getFormElement() { if (!empty($this->config['form_type'])) { if (!in_array($this->config['form_type'], $this->databaseTypeToFormType)) { throw new FactoryException('Unknown form type ' . $this->config['form_type']); } $formElementType = $this->config['form_type']; } else { if (!array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) { throw new FactoryException('No form type found for database type ' . $this->column->getType()->getName()); } $formElementType = $this->databaseTypeToFormType[$this->column->getType()->getName()]; } if (isset($this->config['defaults']) && is_array($this->config['defaults'])) { $formElementType = 'select'; } $formElement = $this->factory->get($formElementType, []); if (!empty($this->config['attr']) && is_array($this->config['attr'])) { $formElement->attr($this->config['attr']); } if ($formElementType !== 'hidden') { $formElement->class('form-control')->label($this->getPresentation())->placeholder($this->getPresentation()); } if ($formElementType === 'textarea') { $formElement->class('form-control ' . config('anavel-crud.text_editor')); } if ($formElementType === 'checkbox') { $formElement->class('checkbox'); } if (isset($this->config['defaults'])) { if (!is_array($this->config['defaults'])) { $formElement->val(transcrud($this->config['defaults'])); } else { $defaults = []; foreach ($this->config['defaults'] as $key => $default) { $defaults[$key] = transcrud($default); } $formElement->options($defaults); } } return $formElement; }
/** * Metodo responsavel por recuperar o maxlength * * @param Column $objColumn * @return int|null */ private function getMaxlength($objColumn) { $intMaxLength = 0; $objType = $objColumn->getType(); if ($objType instanceof IntegerType) { $intMaxLength = $objColumn->getPrecision(); } elseif ($objType instanceof StringType) { $intMaxLength = $objColumn->getLength(); } elseif ($objType instanceof DateTimeType) { $intMaxLength = 0; } elseif ($objType instanceof FloatType) { $intMaxLength = $objColumn->getPrecision(); } return $intMaxLength; }
protected function getType(Column $column) { $type = 0; if ($column->getLength() > 0) { $type += $column->getLength(); } $type = $type | SerializeTrait::getTypeByDoctrineType($column->getType()); if (!$column->getNotnull()) { $type = $type | TableInterface::IS_NULL; } if ($column->getAutoincrement()) { $type = $type | TableInterface::AUTO_INCREMENT; } return $type; }
/** * @param string $tableName * @param string $columnName * @param \Doctrine\DBAL\Schema\Column $column * @return array */ protected function getAddColumnSQL($tableName, $columnName, Column $column) { $query = array(); $spatial = array('srid' => 4326, 'dimension' => 2, 'index' => false); foreach ($spatial as $key => &$val) { if ($column->hasCustomSchemaOption('spatial_' . $key)) { $val = $column->getCustomSchemaOption('spatial_' . $key); } } // Geometry columns are created by AddGeometryColumn stored procedure $query[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $tableName, $columnName, $spatial['srid'], strtoupper($column->getType()->getName()), $spatial['dimension']); if ($spatial['index']) { // Add a spatial index to the field $query[] = sprintf("Select CreateSpatialIndex('%s', '%s')", $tableName, $columnName); } return $query; }
/** * @param Column $column * @param Collection $foreignKeyColumns * @param Collection $foreignTables * @param Collection $indexes * @return ColumnInterface */ protected function buildColumn(Column $column, Collection $foreignKeyColumns, Collection $foreignTables, Collection $indexes) { $uniqued = $indexes->filter(function (Index $index) use($column) { return $index->getColumns()[0] == $column->getName() && $index->isUnique(); })->count() > 0; if ($column->getAutoincrement()) { return new ColumnAutoincrement($column, null, null, $uniqued); } else { if ($foreignKeyColumns->has($column->getName())) { $table = $foreignKeyColumns->get($column->getName()); return new ColumnSelect($column, $table, $foreignTables->get($table), $uniqued); } else { if ($column->getType()->getName() == Type::INTEGER) { return new ColumnNumericText($column, null, null, $uniqued); } else { return new ColumnText($column, null, null, $uniqued); } } } }
/** * Is carbon cast field. * * @param Column $column * @param bool $hasTimestamps * @return bool */ protected function isCarbonField(Column $column, $hasTimestamps) { if (in_array($column->getType()->getName(), $this->carbon['types'])) { $fields = array_merge([$this->deletedAtColumn], $this->carbon['fields']); if ($hasTimestamps) { $fields = array_merge($fields, $this->timestamps); } return !in_array($column->getName(), $fields); } return false; }
/** * Set the type of a column. * * @param mixed $type * @return $this */ public function getType() { $type = $this->column->getType(); return $type->getName(); }
/** * Get the field type for a given column. * * @param string $name * @param \Doctrine\DBAL\Schema\Column $column * @param null $field Optional field value for repeaters/array based columns * * @return string */ public function getFieldTypeFor($name, $column, $field = null) { if ($column instanceof Column) { if ($column->getType()) { $type = get_class($column->getType()); } $column = $column->getName(); } if ($field !== null) { if (isset($this->contenttypes[$name]) && isset($this->contenttypes[$name]['fields'][$column]['fields'][$field])) { $type = $this->contenttypes[$name]['fields'][$column]['fields'][$field]['type']; } } elseif (isset($this->contenttypes[$name]) && isset($this->contenttypes[$name]['fields'][$column])) { $type = $this->contenttypes[$name]['fields'][$column]['type']; } if ($column === 'slug') { $type = 'slug'; } if ($type === 'select' && isset($this->contenttypes[$name]['fields'][$column]['multiple']) && $this->contenttypes[$name]['fields'][$column]['multiple'] === true) { $type = 'selectmultiple'; } if ($type && isset($this->typemap[$type])) { $type = $this->typemap[$type]; } else { $type = $this->typemap['text']; } return $type; }
/** * @param \Doctrine\DBAL\Schema\Column $column * return boolean */ public function isLikeImage($column) { $type = $column->getType()->getName(); $name = $column->getName(); $result = false; if (($name == "image" || $name == "picture") && ($type == "string" || $type == "text")) { $result = true; } return $result; }
/** * Build field mapping from a schema column definition * * @param string $tableName * @param \Doctrine\DBAL\Schema\Column $column * * @return array */ private function buildFieldMapping($tableName, Column $column) { $fieldMapping = array('fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), 'columnName' => $column->getName(), 'type' => $column->getType()->getName(), 'nullable' => !$column->getNotNull()); // Type specific elements switch ($fieldMapping['type']) { case Type::TARRAY: case Type::BLOB: case Type::GUID: case Type::JSON_ARRAY: case Type::OBJECT: case Type::SIMPLE_ARRAY: case Type::STRING: case Type::TEXT: $fieldMapping['length'] = $column->getLength(); $fieldMapping['options']['fixed'] = $column->getFixed(); break; case Type::DECIMAL: case Type::FLOAT: $fieldMapping['precision'] = $column->getPrecision(); $fieldMapping['scale'] = $column->getScale(); break; case Type::INTEGER: case Type::BIGINT: case Type::SMALLINT: $fieldMapping['options']['unsigned'] = $column->getUnsigned(); break; } // Comment if (($comment = $column->getComment()) !== null) { $fieldMapping['options']['comment'] = $comment; } // Weather if (($default = $column->getDefault()) !== null) { $fieldMapping['options']['default'] = $default; } return $fieldMapping; }
/** * Get the field type for a given column. * * @param string $name * @param \Doctrine\DBAL\Schema\Column $column * * @return string */ protected function getFieldTypeFor($name, $column) { if (isset($this->contenttypes[$name]['fields'][$column->getName()])) { $type = $this->contenttypes[$name]['fields'][$column->getName()]['type']; } elseif ($column->getType()) { $type = get_class($column->getType()); } if ($column->getName() === 'slug') { $type = 'slug'; } if ($type === 'select' && isset($this->contenttypes[$name]['fields'][$column->getName()]['multiple']) && $this->contenttypes[$name]['fields'][$column->getName()]['multiple'] === true) { $type = 'selectmultiple'; } if (isset($this->typemap[$type])) { $type = $this->typemap[$type]; } else { $type = $this->typemap['text']; } return $type; }
/** * @param Column $column * @param \SimpleXMLElement $xml */ private static function saveColumn($column, $xml) { $xml->addChild('name', $column->getName()); switch ($column->getType()) { case 'SmallInt': case 'Integer': case 'BigInt': $xml->addChild('type', 'integer'); $default = $column->getDefault(); if (is_null($default) && $column->getAutoincrement()) { $default = '0'; } $xml->addChild('default', $default); $xml->addChild('notnull', self::toBool($column->getNotnull())); if ($column->getAutoincrement()) { $xml->addChild('autoincrement', '1'); } if ($column->getUnsigned()) { $xml->addChild('unsigned', 'true'); } $length = '4'; if ($column->getType() == 'SmallInt') { $length = '2'; } elseif ($column->getType() == 'BigInt') { $length = '8'; } $xml->addChild('length', $length); break; case 'String': $xml->addChild('type', 'text'); $default = trim($column->getDefault()); if ($default === '') { $default = false; } $xml->addChild('default', $default); $xml->addChild('notnull', self::toBool($column->getNotnull())); $xml->addChild('length', $column->getLength()); break; case 'Text': $xml->addChild('type', 'clob'); $xml->addChild('notnull', self::toBool($column->getNotnull())); break; case 'Decimal': $xml->addChild('type', 'decimal'); $xml->addChild('default', $column->getDefault()); $xml->addChild('notnull', self::toBool($column->getNotnull())); $xml->addChild('length', '15'); break; case 'Boolean': $xml->addChild('type', 'integer'); $xml->addChild('default', $column->getDefault()); $xml->addChild('notnull', self::toBool($column->getNotnull())); $xml->addChild('length', '1'); break; case 'DateTime': $xml->addChild('type', 'timestamp'); $xml->addChild('default', $column->getDefault()); $xml->addChild('notnull', self::toBool($column->getNotnull())); break; } }
/** * @param Column $column * @return string * @throws \RuntimeException */ private function doctrineColumnToProcessingType(Column $column) { if (!isset($this->doctrineProcessingTypeMap[$column->getType()->getName()])) { throw new \RuntimeException(sprintf("No processing type mapping for doctrine type %s", $column->getType()->getName())); } $processingType = $this->doctrineProcessingTypeMap[$column->getType()->getName()]; if (!$column->getNotnull() || $column->getAutoincrement()) { $processingType .= "OrNull"; if (!class_exists($processingType)) { throw new \RuntimeException("Missing null type: for nullable column: " . $column->getName()); } } Assertion::implementsInterface($processingType, 'Prooph\\Processing\\Type\\Type'); return $processingType; }
/** * {@inheritdoc} */ protected function _getPortableTableColumnDefinition($tableColumn) { $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); if (strtolower($tableColumn['type']) === 'varchar' || strtolower($tableColumn['type']) === 'bpchar') { // get length from varchar definition $length = preg_replace('~.*\\(([0-9]*)\\).*~', '$1', $tableColumn['complete_type']); $tableColumn['length'] = $length; } $matches = array(); $autoincrement = false; if (preg_match("/^nextval\\('(.*)'(::.*)?\\)\$/", $tableColumn['default'], $matches)) { $tableColumn['sequence'] = $matches[1]; $tableColumn['default'] = null; $autoincrement = true; } if (preg_match("/^'(.*)'::.*\$/", $tableColumn['default'], $matches)) { $tableColumn['default'] = $matches[1]; } if (stripos($tableColumn['default'], 'NULL') === 0) { $tableColumn['default'] = null; } $length = isset($tableColumn['length']) ? $tableColumn['length'] : null; if ($length == '-1' && isset($tableColumn['atttypmod'])) { $length = $tableColumn['atttypmod'] - 4; } if ((int) $length <= 0) { $length = null; } $fixed = null; if (!isset($tableColumn['name'])) { $tableColumn['name'] = ''; } $precision = null; $scale = null; $jsonb = null; $dbType = strtolower($tableColumn['type']); if (strlen($tableColumn['domain_type']) && !$this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) { $dbType = strtolower($tableColumn['domain_type']); $tableColumn['complete_type'] = $tableColumn['domain_complete_type']; } $type = $this->_platform->getDoctrineTypeMapping($dbType); $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type); $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type); switch ($dbType) { case 'smallint': case 'int2': $length = null; break; case 'int': case 'int4': case 'integer': $length = null; break; case 'bigint': case 'int8': $length = null; break; case 'bool': case 'boolean': if ($tableColumn['default'] === 'true') { $tableColumn['default'] = true; } if ($tableColumn['default'] === 'false') { $tableColumn['default'] = false; } $length = null; break; case 'text': $fixed = false; break; case 'varchar': case 'interval': case '_varchar': $fixed = false; break; case 'char': case 'bpchar': $fixed = true; break; case 'float': case 'float4': case 'float8': case 'double': case 'double precision': case 'real': case 'decimal': case 'money': case 'numeric': if (preg_match('([A-Za-z]+\\(([0-9]+)\\,([0-9]+)\\))', $tableColumn['complete_type'], $match)) { $precision = $match[1]; $scale = $match[2]; $length = null; } break; case 'year': $length = null; break; // PostgreSQL 9.4+ only // PostgreSQL 9.4+ only case 'jsonb': $jsonb = true; break; } if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) { $tableColumn['default'] = $match[1]; } $options = array('length' => $length, 'notnull' => (bool) $tableColumn['isnotnull'], 'default' => $tableColumn['default'], 'primary' => (bool) ($tableColumn['pri'] == 't'), 'precision' => $precision, 'scale' => $scale, 'fixed' => $fixed, 'unsigned' => false, 'autoincrement' => $autoincrement, 'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null); $column = new Column($tableColumn['field'], Type::getType($type), $options); if (isset($tableColumn['collation']) && !empty($tableColumn['collation'])) { $column->setPlatformOption('collation', $tableColumn['collation']); } if ($column->getType()->getName() === 'json_array') { $column->setPlatformOption('jsonb', $jsonb); } return $column; }
/** * @param $column * @return array */ protected function formatColumn(Column $column) { return ['type' => $column->getType()->getName(), 'required' => $column->getNotnull(), 'default' => $column->getDefault()]; }
protected function convertDoctrineTypeToString(Column $column, $isPrimary) { $type = SerializeTrait::getTypeByDoctrineType($column->getType()); $name = $column->getName(); switch ($type) { case TableInterface::TYPE_BIGINT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_BIGINT PHP; break; case TableInterface::TYPE_BLOB: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_BLOB PHP; break; case TableInterface::TYPE_BOOLEAN: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_BOOLEAN PHP; break; case TableInterface::TYPE_DATETIME: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_DATETIME PHP; break; case TableInterface::TYPE_DATE: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_DATE PHP; break; case TableInterface::TYPE_DECIMAL: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_DECIMAL PHP; break; case TableInterface::TYPE_FLOAT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_FLOAT PHP; break; case TableInterface::TYPE_INT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_INT PHP; break; case TableInterface::TYPE_SMALLINT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_SMALLINT PHP; break; case TableInterface::TYPE_TEXT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_TEXT PHP; break; case TableInterface::TYPE_ARRAY: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_ARRAY PHP; break; case TableInterface::TYPE_OBJECT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_OBJECT PHP; break; case TableInterface::TYPE_TIME: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_TIME PHP; break; case TableInterface::TYPE_VARCHAR: default: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_VARCHAR PHP; break; } if ($column->getAutoincrement()) { $result .= ' | self::AUTO_INCREMENT'; } if ($isPrimary) { $result .= ' | self::PRIMARY_KEY'; } return $result . ','; }
/** * @param Column $column * @return string */ protected function guessFormItemType(Column $column) { $name = $column->getName(); $foreignKey = $this->getForeignKey($name); if (!is_null($foreignKey)) { return 'select'; } $type = $column->getType()->getName(); if ($type == 'string' && $this->isEnumColumn($name)) { return 'select'; } $lookup = ['string' => 'text', 'text' => 'ckeditor', 'integer' => 'text', 'float' => 'text', 'boolean' => 'checkbox', 'date' => 'date', 'time' => 'time', 'datetime' => 'timestamp']; return Arr::get($lookup, $type, 'text'); }
/** * @param string $tableName * @param string $columnName * @param \Doctrine\DBAL\Schema\Column $column * @return array */ protected function getAddColumnSQL($tableName, $columnName, Column $column) { $query = array(); $spatial = array('srid' => 4326, 'dimension' => 2, 'index' => false); foreach ($spatial as $key => &$val) { if ($column->hasCustomSchemaOption('spatial_' . $key)) { $val = $column->getCustomSchemaOption('spatial_' . $key); } } // Geometry columns are created by AddGeometryColumn stored procedure $query[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $tableName, $columnName, $spatial['srid'], strtoupper($column->getType()->getName()), $spatial['dimension']); if ($spatial['index']) { // Add a spatial index to the field $indexName = $this->generateIndexName($tableName, $columnName); $query[] = sprintf("CREATE INDEX %s ON %s USING GIST (%s)", $indexName, $tableName, $columnName); } if ($column->getNotnull()) { // Add a NOT NULL constraint to the field $query[] = sprintf("ALTER TABLE %s ALTER %s SET NOT NULL", $tableName, $columnName); } return $query; }
public function type() { return $this->dbal->getType(); }
/** * Populates attributes. * * @param Attrs $attrs * @param string $key * @param Column $column */ private function populateColumn($attrs, $key, $column) { $attrs->set($this->deriveName($key), ['key' => $key, 'type' => $column->getType()->getName(), 'default' => $column->getDefault(), 'nullable' => !$column->getNotnull()]); }
/** * Return the comment of a passed column modified by potential doctrine type comment hints. * * @param Column $column * @return string */ protected function getColumnComment(Column $column) { $comment = $column->getComment(); if ($this->isCommentedDoctrineType($column->getType())) { $comment .= $this->getDoctrineTypeComment($column->getType()); } return $comment; }
/** * @param Table $table * @param string $columnName * @param Column $targetColumn * @param array $options * @throws \Doctrine\DBAL\Schema\SchemaException */ protected function addRelationColumn(Table $table, $columnName, Column $targetColumn, array $options = []) { if ($targetColumn->getName() !== 'id') { throw new SchemaException(sprintf('The target column name must be "id". Relation column: "%s::%s". Target column name: "%s".', $table->getName(), $columnName, $targetColumn->getName())); } $columnTypeName = $targetColumn->getType()->getName(); if (!in_array($columnTypeName, [Type::INTEGER, Type::STRING, Type::SMALLINT, Type::BIGINT])) { throw new SchemaException(sprintf('The type of relation column "%s::%s" must be an integer or string. "%s" type is not supported.', $table->getName(), $columnName, $columnTypeName)); } if ($columnTypeName === Type::STRING && $targetColumn->getLength() !== null) { $options['length'] = $targetColumn->getLength(); } $table->addColumn($columnName, $columnTypeName, $options); }
/** * Set the renamed columns on the table diff. * * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff * @param \Illuminate\Support\Fluent $command * @param \Doctrine\DBAL\Schema\Column $column * @return \Doctrine\DBAL\Schema\TableDiff */ protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column) { $newColumn = new Column($command->to, $column->getType(), $column->toArray()); $tableDiff->renamedColumns = array($command->from => $newColumn); return $tableDiff; }
/** * Process primary key of the table field. * * @param Column $column * @return string */ protected function processPrimaryKey(Column $column) { return $this->grammar->primaryKey($column->getName(), $column->getType()->getName()); }
/** * Get the field type for a given column. * * @param string $name * @param \Doctrine\DBAL\Schema\Column $column * * @return string */ protected function getFieldTypeFor($name, $column) { $contentKey = $this->schemaManager->getKeyForTable($name); if ($contentKey && isset($this->contenttypes[$contentKey]['fields'][$column->getName()])) { $type = $this->contenttypes[$contentKey]['fields'][$column->getName()]['type']; } elseif ($column->getType()) { $type = get_class($column->getType()); } if ($type === 'select' && isset($this->contenttypes[$contentKey]['fields'][$column->getName()]['multiple']) && $this->contenttypes[$contentKey]['fields'][$column->getName()]['multiple'] === true) { $type = 'selectmultiple'; } if (isset($this->typemap[$type])) { $type = $this->typemap[$type]; } else { $type = $this->typemap['text']; } return $type; }
/** * @param \Doctrine\DBAL\Schema\Column $column The name of the table. * @param array $primaries * * @return array The column data as associative array. */ public function prepareColumnData($column, $primaries = array()) { $columnData = array(); $columnData['name'] = $column->getQuotedName($this); $columnData['type'] = $column->getType(); $columnData['length'] = $column->getLength(); $columnData['notnull'] = $column->getNotNull(); $columnData['fixed'] = $column->getFixed(); $columnData['unique'] = false; // TODO: what do we do about this? $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false; if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) { $columnData['length'] = 255; } $columnData['unsigned'] = $column->getUnsigned(); $columnData['precision'] = $column->getPrecision(); $columnData['scale'] = $column->getScale(); $columnData['default'] = $column->getDefault(); $columnData['columnDefinition'] = $column->getColumnDefinition(); $columnData['autoincrement'] = $column->getAutoincrement(); $columnData['comment'] = $this->getColumnComment($column); $columnData['platformOptions'] = $column->getPlatformOptions(); if (in_array($column->getName(), $primaries)) { $columnData['primary'] = true; } return $columnData; }