Fixes #14638: Added yii\db\SchemaBuilderTrait::tinyInteger()

This commit is contained in:
Robert Korulczyk
2018-02-12 10:01:21 +01:00
committed by Alexander Makarov
parent 74dc1cdc30
commit df91a9608f
24 changed files with 108 additions and 13 deletions

View File

@ -91,6 +91,7 @@ class ColumnSchemaBuilder extends BaseObject
Schema::TYPE_CHAR => self::CATEGORY_STRING,
Schema::TYPE_STRING => self::CATEGORY_STRING,
Schema::TYPE_TEXT => self::CATEGORY_STRING,
Schema::TYPE_TINYINT => self::CATEGORY_NUMERIC,
Schema::TYPE_SMALLINT => self::CATEGORY_NUMERIC,
Schema::TYPE_INTEGER => self::CATEGORY_NUMERIC,
Schema::TYPE_BIGINT => self::CATEGORY_NUMERIC,

View File

@ -49,6 +49,7 @@ abstract class Schema extends BaseObject
const TYPE_CHAR = 'char';
const TYPE_STRING = 'string';
const TYPE_TEXT = 'text';
const TYPE_TINYINT = 'tinyint';
const TYPE_SMALLINT = 'smallint';
const TYPE_INTEGER = 'integer';
const TYPE_BIGINT = 'bigint';
@ -615,14 +616,15 @@ abstract class Schema extends BaseObject
{
static $typeMap = [
// abstract type => php type
'smallint' => 'integer',
'integer' => 'integer',
'bigint' => 'integer',
'boolean' => 'boolean',
'float' => 'double',
'double' => 'double',
'binary' => 'resource',
'json' => 'array',
self::TYPE_TINYINT => 'integer',
self::TYPE_SMALLINT => 'integer',
self::TYPE_INTEGER => 'integer',
self::TYPE_BIGINT => 'integer',
self::TYPE_BOOLEAN => 'boolean',
self::TYPE_FLOAT => 'double',
self::TYPE_DOUBLE => 'double',
self::TYPE_BINARY => 'resource',
self::TYPE_JSON => 'array',
];
if (isset($typeMap[$column->type])) {
if ($column->type === 'bigint') {

View File

@ -97,6 +97,18 @@ trait SchemaBuilderTrait
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_TEXT);
}
/**
* Creates a tinyint column. If tinyint is not supported by the DBMS, smallint will be used.
* @param int $length column size or precision definition.
* This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.14
*/
public function tinyInteger($length = null)
{
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_TINYINT, $length);
}
/**
* Creates a smallint column.
* @param int $length column size or precision definition.

View File

@ -32,6 +32,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'varchar',
Schema::TYPE_TINYINT => 'smallint',
Schema::TYPE_SMALLINT => 'smallint',
Schema::TYPE_INTEGER => 'int',
Schema::TYPE_BIGINT => 'bigint',

View File

@ -30,6 +30,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_CHAR => 'nchar(1)',
Schema::TYPE_STRING => 'nvarchar(255)',
Schema::TYPE_TEXT => 'nvarchar(max)',
Schema::TYPE_TINYINT => 'tinyint',
Schema::TYPE_SMALLINT => 'smallint',
Schema::TYPE_INTEGER => 'int',
Schema::TYPE_BIGINT => 'bigint',

View File

@ -45,7 +45,7 @@ class Schema extends \yii\db\Schema implements ConstraintFinderInterface
'decimal' => self::TYPE_DECIMAL,
'smallmoney' => self::TYPE_MONEY,
'int' => self::TYPE_INTEGER,
'tinyint' => self::TYPE_SMALLINT,
'tinyint' => self::TYPE_TINYINT,
'money' => self::TYPE_MONEY,
// approximate numbers
'float' => self::TYPE_FLOAT,

View File

@ -32,6 +32,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'text',
Schema::TYPE_TINYINT => 'tinyint(3)',
Schema::TYPE_SMALLINT => 'smallint(6)',
Schema::TYPE_INTEGER => 'int(11)',
Schema::TYPE_BIGINT => 'bigint(20)',

View File

@ -40,7 +40,7 @@ class Schema extends \yii\db\Schema implements ConstraintFinderInterface
* @var array mapping from physical column types (keys) to abstract column types (values)
*/
public $typeMap = [
'tinyint' => self::TYPE_SMALLINT,
'tinyint' => self::TYPE_TINYINT,
'bit' => self::TYPE_INTEGER,
'smallint' => self::TYPE_SMALLINT,
'mediumint' => self::TYPE_INTEGER,

View File

@ -35,6 +35,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_CHAR => 'CHAR(1)',
Schema::TYPE_STRING => 'VARCHAR2(255)',
Schema::TYPE_TEXT => 'CLOB',
Schema::TYPE_TINYINT => 'NUMBER(3)',
Schema::TYPE_SMALLINT => 'NUMBER(5)',
Schema::TYPE_INTEGER => 'NUMBER(10)',
Schema::TYPE_BIGINT => 'NUMBER(20)',

View File

@ -59,6 +59,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'text',
Schema::TYPE_TINYINT => 'smallint',
Schema::TYPE_SMALLINT => 'smallint',
Schema::TYPE_INTEGER => 'integer',
Schema::TYPE_BIGINT => 'bigint',

View File

@ -35,6 +35,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'text',
Schema::TYPE_TINYINT => 'tinyint',
Schema::TYPE_SMALLINT => 'smallint',
Schema::TYPE_INTEGER => 'integer',
Schema::TYPE_BIGINT => 'bigint',

View File

@ -38,7 +38,7 @@ class Schema extends \yii\db\Schema implements ConstraintFinderInterface
* @var array mapping from physical column types (keys) to abstract column types (values)
*/
public $typeMap = [
'tinyint' => self::TYPE_SMALLINT,
'tinyint' => self::TYPE_TINYINT,
'bit' => self::TYPE_SMALLINT,
'boolean' => self::TYPE_BOOLEAN,
'bool' => self::TYPE_BOOLEAN,