Skip to content

Commit

Permalink
fix boolean type and table comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Hzhihua committed Feb 1, 2018
1 parent 28399ff commit c876400
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions src/models/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ public function getTableComment(TableSchema $table, $indent = 0)

foreach ($this->_tableStatus as $value) {
if ($table->name === $value['Name'] && ! empty($value['Comment'])) {
return $definition . "\$this->addCommentOnTable('{{%$tableName}}', '{$value['Comment']}');";
$comment = addslashes($value['Comment']);
return $definition . "\$this->addCommentOnTable('{{%$tableName}}', '{$comment}');";
}
}

Expand Down Expand Up @@ -599,49 +600,45 @@ public function FKOnParams($string)
*/
public static function getSchemaType(ColumnSchema $column)
{
$type = '';

// boolean
if ('tinyint(1)' === $column->dbType) {
return 'boolean()';
}

// smallint
if ('smallint' === $column->type) {
if (null === $column->size) {
return 'smallInteger()';
}
return 'smallInteger';
}

// integer
if ('int' === $column->type) {
if (null === $column->size) {
return 'integer()';
}
return 'integer';
}

// bigint
if ('bigint' === $column->type) {
if (null === $column->size) {
return 'bigInteger()';
}
return 'bigInteger';
}

// enum
if (null !== $column->enumValues) {
// https://github.com/yiisoft/yii2/issues/9797
$enumValues = array_map('addslashes', $column->enumValues);
return "enum(['".implode('\', \'', $enumValues)."'])";
}

switch ($column->type) {
case 'smallint':
$type = 'smallInteger';
break;

case 'int':
$type = 'integer';
break;

case 'bigint':
$type = 'bigInteger';
break;

default:
$type = $column->type;
break;
}

// others
if (null === $column->size && 0 >= $column->scale) {
return $column->type.'()';
if (null === $column->size) {
return "$type()";
} else {
return "{$type}({$column->size})";
}

return $column->type;
}

/**
Expand All @@ -653,14 +650,6 @@ public static function other(ColumnSchema $column)
{
$definition = '';

// size
if (null !== $column->scale && 0 < $column->scale) {
$definition .= "($column->precision,$column->scale)";

} elseif (null !== $column->size) {
$definition .= "($column->size)";
}

// unsigned
if ($column->unsigned) {
$definition .= '->unsigned()';
Expand Down

0 comments on commit c876400

Please sign in to comment.