diff --git a/src/models/Schema.php b/src/models/Schema.php index a739996..80eb50f 100644 --- a/src/models/Schema.php +++ b/src/models/Schema.php @@ -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}');"; } } @@ -599,36 +600,13 @@ 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 @@ -636,12 +614,31 @@ public static function getSchemaType(ColumnSchema $column) 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; } /** @@ -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()';