/** * 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). $result['default'] = $default === '' ? null : $default; return $result; }
protected function generateDefaultMethodCall($default, $column) { $columnName = $column->getName(); $typeName = $column->getType()->getName(); $type = MigrationColumnType::toMigrationMethodName($typeName, $columnName); if (in_array($type, MigrationColumnType::getIntegerTypes()) || in_array($type, MigrationColumnType::getDecimalTypes()) || $type == MigrationColumnType::TYPE_BOOLEAN) { return sprintf('->default(%s)', $default); } return sprintf('->default(\'%s\')', $this->quoteParameter($default)); }
protected function loadColumnsFromTableInfo() { $this->columns = []; $columns = $this->tableInfo->getColumns(); $primaryKey = $this->tableInfo->getPrimaryKey(); $primaryKeyColumns = []; if ($primaryKey) { $primaryKeyColumns = $primaryKey->getColumns(); } foreach ($columns as $column) { $columnName = $column->getName(); $typeName = $column->getType()->getName(); if ($typeName == EnumDbType::TYPENAME) { throw new ApplicationException(Lang::get('rainlab.builder::lang.database.error_enum_not_supported')); } $item = ['name' => $columnName, 'type' => MigrationColumnType::toMigrationMethodName($typeName, $columnName), 'length' => MigrationColumnType::doctrineLengthToMigrationLength($column), 'unsigned' => $column->getUnsigned(), 'allow_null' => !$column->getNotnull(), 'auto_increment' => $column->getAutoincrement(), 'primary_key' => in_array($columnName, $primaryKeyColumns), 'default' => $column->getDefault(), 'id' => $columnName]; $this->columns[] = $item; } }
protected function loadColumnsFromTableInfo() { $this->columns = []; $columns = $this->tableInfo->getColumns(); $primaryKey = $this->tableInfo->getPrimaryKey(); $primaryKeyColumns = []; if ($primaryKey) { $primaryKeyColumns = $primaryKey->getColumns(); } foreach ($columns as $column) { $columnName = $column->getName(); $typeName = $column->getType()->getName(); $item = ['name' => $columnName, 'type' => MigrationColumnType::toMigrationMethodName($typeName, $columnName), 'length' => MigrationColumnType::doctrineLengthToMigrationLength($column), 'unsigned' => $column->getUnsigned(), 'allow_null' => !$column->getNotnull(), 'auto_increment' => $column->getAutoincrement(), 'primary_key' => in_array($columnName, $primaryKeyColumns), 'default' => $column->getDefault(), 'id' => $columnName]; $this->columns[] = $item; } }