Browse Source

Merge pull request #10668 from cakephp/3next-type-constants

RFC - 3.next Abstract schema type constants
Mark Story 8 years ago
parent
commit
c1dac4d08f

+ 53 - 37
src/Database/Schema/MysqlSchema.php

@@ -15,6 +15,7 @@
 namespace Cake\Database\Schema;
 
 use Cake\Database\Exception;
+use Cake\Database\Schema\TableSchema;
 
 /**
  * Schema generation/reflection features for MySQL
@@ -96,46 +97,46 @@ class MysqlSchema extends BaseSchema
             return ['type' => $col, 'length' => null];
         }
         if (($col === 'tinyint' && $length === 1) || $col === 'boolean') {
-            return ['type' => 'boolean', 'length' => null];
+            return ['type' => TableSchema::TYPE_BOOLEAN, 'length' => null];
         }
 
         $unsigned = (isset($matches[3]) && strtolower($matches[3]) === 'unsigned');
         if (strpos($col, 'bigint') !== false || $col === 'bigint') {
-            return ['type' => 'biginteger', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_BIGINTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if ($col === 'tinyint') {
-            return ['type' => 'tinyinteger', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_TINYINTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if ($col === 'smallint') {
-            return ['type' => 'smallinteger', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_SMALLINTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if (in_array($col, ['int', 'integer', 'mediumint'])) {
-            return ['type' => 'integer', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_INTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if ($col === 'char' && $length === 36) {
-            return ['type' => 'uuid', 'length' => null];
+            return ['type' => TableSchema::TYPE_UUID, 'length' => null];
         }
         if ($col === 'char') {
-            return ['type' => 'string', 'fixed' => true, 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'fixed' => true, 'length' => $length];
         }
         if (strpos($col, 'char') !== false) {
-            return ['type' => 'string', 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'length' => $length];
         }
         if (strpos($col, 'text') !== false) {
             $lengthName = substr($col, 0, -4);
             $length = isset(Table::$columnLengths[$lengthName]) ? Table::$columnLengths[$lengthName] : null;
 
-            return ['type' => 'text', 'length' => $length];
+            return ['type' => TableSchema::TYPE_TEXT, 'length' => $length];
         }
         if (strpos($col, 'blob') !== false || $col === 'binary') {
             $lengthName = substr($col, 0, -4);
             $length = isset(Table::$columnLengths[$lengthName]) ? Table::$columnLengths[$lengthName] : null;
 
-            return ['type' => 'binary', 'length' => $length];
+            return ['type' => TableSchema::TYPE_BINARY, 'length' => $length];
         }
         if (strpos($col, 'float') !== false || strpos($col, 'double') !== false) {
             return [
-                'type' => 'float',
+                'type' => TableSchema::TYPE_FLOAT,
                 'length' => $length,
                 'precision' => $precision,
                 'unsigned' => $unsigned
@@ -143,7 +144,7 @@ class MysqlSchema extends BaseSchema
         }
         if (strpos($col, 'decimal') !== false) {
             return [
-                'type' => 'decimal',
+                'type' => TableSchema::TYPE_DECIMAL,
                 'length' => $length,
                 'precision' => $precision,
                 'unsigned' => $unsigned
@@ -151,10 +152,10 @@ class MysqlSchema extends BaseSchema
         }
 
         if (strpos($col, 'json') !== false) {
-            return ['type' => 'json', 'length' => null];
+            return ['type' => TableSchema::TYPE_JSON, 'length' => null];
         }
 
-        return ['type' => 'string', 'length' => null];
+        return ['type' => TableSchema::TYPE_STRING, 'length' => null];
     }
 
     /**
@@ -303,19 +304,19 @@ class MysqlSchema extends BaseSchema
         $nativeJson = $this->_driver->supportsNativeJson();
 
         $typeMap = [
-            'tinyinteger' => ' TINYINT',
-            'smallinteger' => ' SMALLINT',
-            'integer' => ' INTEGER',
-            'biginteger' => ' BIGINT',
-            'boolean' => ' BOOLEAN',
-            'float' => ' FLOAT',
-            'decimal' => ' DECIMAL',
-            'date' => ' DATE',
-            'time' => ' TIME',
-            'datetime' => ' DATETIME',
-            'timestamp' => ' TIMESTAMP',
-            'uuid' => ' CHAR(36)',
-            'json' => $nativeJson ? ' JSON' : ' LONGTEXT'
+            TableSchema::TYPE_TINYINTEGER => ' TINYINT',
+            TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',
+            TableSchema::TYPE_INTEGER => ' INTEGER',
+            TableSchema::TYPE_BIGINTEGER => ' BIGINT',
+            TableSchema::TYPE_BOOLEAN => ' BOOLEAN',
+            TableSchema::TYPE_FLOAT => ' FLOAT',
+            TableSchema::TYPE_DECIMAL => ' DECIMAL',
+            TableSchema::TYPE_DATE => ' DATE',
+            TableSchema::TYPE_TIME => ' TIME',
+            TableSchema::TYPE_DATETIME => ' DATETIME',
+            TableSchema::TYPE_TIMESTAMP => ' TIMESTAMP',
+            TableSchema::TYPE_UUID => ' CHAR(36)',
+            TableSchema::TYPE_JSON => $nativeJson ? ' JSON' : ' LONGTEXT'
         ];
         $specialMap = [
             'string' => true,
@@ -327,13 +328,13 @@ class MysqlSchema extends BaseSchema
         }
         if (isset($specialMap[$data['type']])) {
             switch ($data['type']) {
-                case 'string':
+                case TableSchema::TYPE_STRING:
                     $out .= !empty($data['fixed']) ? ' CHAR' : ' VARCHAR';
                     if (!isset($data['length'])) {
                         $data['length'] = 255;
                     }
                     break;
-                case 'text':
+                case TableSchema::TYPE_TEXT:
                     $isKnownLength = in_array($data['length'], Table::$columnLengths);
                     if (empty($data['length']) || !$isKnownLength) {
                         $out .= ' TEXT';
@@ -346,7 +347,7 @@ class MysqlSchema extends BaseSchema
                     }
 
                     break;
-                case 'binary':
+                case TableSchema::TYPE_BINARY:
                     $isKnownLength = in_array($data['length'], Table::$columnLengths);
                     if (empty($data['length']) || !$isKnownLength) {
                         $out .= ' BLOB';
@@ -361,26 +362,41 @@ class MysqlSchema extends BaseSchema
                     break;
             }
         }
-        $hasLength = ['integer', 'smallinteger', 'tinyinteger', 'string'];
+        $hasLength = [
+            TableSchema::TYPE_INTEGER,
+            TableSchema::TYPE_SMALLINTEGER,
+            TableSchema::TYPE_TINYINTEGER,
+            TableSchema::TYPE_STRING
+        ];
         if (in_array($data['type'], $hasLength, true) && isset($data['length'])) {
             $out .= '(' . (int)$data['length'] . ')';
         }
 
-        $hasPrecision = ['float', 'decimal'];
+        $hasPrecision = [TableSchema::TYPE_FLOAT, TableSchema::TYPE_DECIMAL];
         if (in_array($data['type'], $hasPrecision, true) &&
             (isset($data['length']) || isset($data['precision']))
         ) {
             $out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
         }
 
-        $hasUnsigned = ['float', 'decimal', 'tinyinteger', 'smallinteger', 'integer', 'biginteger'];
+        $hasUnsigned = [
+            TableSchema::TYPE_TINYINTEGER,
+            TableSchema::TYPE_SMALLINTEGER,
+            TableSchema::TYPE_INTEGER,
+            TableSchema::TYPE_BIGINTEGER,
+            TableSchema::TYPE_FLOAT,
+            TableSchema::TYPE_DECIMAL
+        ];
         if (in_array($data['type'], $hasUnsigned, true) &&
             isset($data['unsigned']) && $data['unsigned'] === true
         ) {
             $out .= ' UNSIGNED';
         }
 
-        $hasCollate = ['text', 'string'];
+        $hasCollate = [
+            TableSchema::TYPE_TEXT,
+            TableSchema::TYPE_STRING,
+        ];
         if (in_array($data['type'], $hasCollate, true) && isset($data['collate']) && $data['collate'] !== '') {
             $out .= ' COLLATE ' . $data['collate'];
         }
@@ -392,17 +408,17 @@ class MysqlSchema extends BaseSchema
             [$name] == (array)$schema->primaryKey() &&
             !$schema->hasAutoincrement()
         );
-        if (in_array($data['type'], ['integer', 'biginteger']) &&
+        if (in_array($data['type'], [TableSchema::TYPE_INTEGER, TableSchema::TYPE_BIGINTEGER]) &&
             ($data['autoIncrement'] === true || $addAutoIncrement)
         ) {
             $out .= ' AUTO_INCREMENT';
         }
-        if (isset($data['null']) && $data['null'] === true && $data['type'] === 'timestamp') {
+        if (isset($data['null']) && $data['null'] === true && $data['type'] === TableSchema::TYPE_TIMESTAMP) {
             $out .= ' NULL';
             unset($data['default']);
         }
         if (isset($data['default']) &&
-            in_array($data['type'], ['timestamp', 'datetime']) &&
+            in_array($data['type'], [TableSchema::TYPE_TIMESTAMP, TableSchema::TYPE_DATETIME]) &&
             strtolower($data['default']) === 'current_timestamp'
         ) {
             $out .= ' DEFAULT CURRENT_TIMESTAMP';

+ 42 - 38
src/Database/Schema/PostgresSchema.php

@@ -15,6 +15,7 @@
 namespace Cake\Database\Schema;
 
 use Cake\Database\Exception;
+use Cake\Database\Schema\TableSchema;
 
 /**
  * Schema management/reflection features for Postgres.
@@ -90,56 +91,56 @@ class PostgresSchema extends BaseSchema
             return ['type' => $col, 'length' => null];
         }
         if (strpos($col, 'timestamp') !== false) {
-            return ['type' => 'timestamp', 'length' => null];
+            return ['type' => TableSchema::TYPE_TIMESTAMP, 'length' => null];
         }
         if (strpos($col, 'time') !== false) {
-            return ['type' => 'time', 'length' => null];
+            return ['type' => TableSchema::TYPE_TIME, 'length' => null];
         }
         if ($col === 'serial' || $col === 'integer') {
-            return ['type' => 'integer', 'length' => 10];
+            return ['type' => TableSchema::TYPE_INTEGER, 'length' => 10];
         }
         if ($col === 'bigserial' || $col === 'bigint') {
-            return ['type' => 'biginteger', 'length' => 20];
+            return ['type' => TableSchema::TYPE_BIGINTEGER, 'length' => 20];
         }
         if ($col === 'smallint') {
-            return ['type' => 'smallinteger', 'length' => 5];
+            return ['type' => TableSchema::TYPE_SMALLINTEGER, 'length' => 5];
         }
         if ($col === 'inet') {
-            return ['type' => 'string', 'length' => 39];
+            return ['type' => TableSchema::TYPE_STRING, 'length' => 39];
         }
         if ($col === 'uuid') {
-            return ['type' => 'uuid', 'length' => null];
+            return ['type' => TableSchema::TYPE_UUID, 'length' => null];
         }
         if ($col === 'char' || $col === 'character') {
-            return ['type' => 'string', 'fixed' => true, 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'fixed' => true, 'length' => $length];
         }
         // money is 'string' as it includes arbitrary text content
         // before the number value.
         if (strpos($col, 'char') !== false ||
             strpos($col, 'money') !== false
         ) {
-            return ['type' => 'string', 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'length' => $length];
         }
         if (strpos($col, 'text') !== false) {
-            return ['type' => 'text', 'length' => null];
+            return ['type' => TableSchema::TYPE_TEXT, 'length' => null];
         }
         if ($col === 'bytea') {
-            return ['type' => 'binary', 'length' => null];
+            return ['type' => TableSchema::TYPE_BINARY, 'length' => null];
         }
         if ($col === 'real' || strpos($col, 'double') !== false) {
-            return ['type' => 'float', 'length' => null];
+            return ['type' => TableSchema::TYPE_FLOAT, 'length' => null];
         }
         if (strpos($col, 'numeric') !== false ||
             strpos($col, 'decimal') !== false
         ) {
-            return ['type' => 'decimal', 'length' => null];
+            return ['type' => TableSchema::TYPE_DECIMAL, 'length' => null];
         }
 
         if (strpos($col, 'json') !== false) {
-            return ['type' => 'json', 'length' => null];
+            return ['type' => TableSchema::TYPE_JSON, 'length' => null];
         }
 
-        return ['type' => 'string', 'length' => null];
+        return ['type' => TableSchema::TYPE_STRING, 'length' => null];
     }
 
     /**
@@ -149,7 +150,7 @@ class PostgresSchema extends BaseSchema
     {
         $field = $this->_convertColumn($row['type']);
 
-        if ($field['type'] === 'boolean') {
+        if ($field['type'] === TableSchema::TYPE_BOOLEAN) {
             if ($row['default'] === 'true') {
                 $row['default'] = 1;
             }
@@ -351,38 +352,40 @@ class PostgresSchema extends BaseSchema
         $data = $schema->column($name);
         $out = $this->_driver->quoteIdentifier($name);
         $typeMap = [
-            'tinyinteger' => ' SMALLINT',
-            'smallinteger' => ' SMALLINT',
-            'boolean' => ' BOOLEAN',
-            'binary' => ' BYTEA',
-            'float' => ' FLOAT',
-            'decimal' => ' DECIMAL',
-            'date' => ' DATE',
-            'time' => ' TIME',
-            'datetime' => ' TIMESTAMP',
-            'timestamp' => ' TIMESTAMP',
-            'uuid' => ' UUID',
-            'json' => ' JSONB'
+            TableSchema::TYPE_TINYINTEGER => ' SMALLINT',
+            TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',
+            TableSchema::TYPE_BINARY => ' BYTEA',
+            TableSchema::TYPE_BOOLEAN => ' BOOLEAN',
+            TableSchema::TYPE_FLOAT => ' FLOAT',
+            TableSchema::TYPE_DECIMAL => ' DECIMAL',
+            TableSchema::TYPE_DATE => ' DATE',
+            TableSchema::TYPE_TIME => ' TIME',
+            TableSchema::TYPE_DATETIME => ' TIMESTAMP',
+            TableSchema::TYPE_TIMESTAMP => ' TIMESTAMP',
+            TableSchema::TYPE_UUID => ' UUID',
+            TableSchema::TYPE_JSON => ' JSONB'
         ];
 
         if (isset($typeMap[$data['type']])) {
             $out .= $typeMap[$data['type']];
         }
 
-        if ($data['type'] === 'integer' || $data['type'] === 'biginteger') {
-            $type = $data['type'] === 'integer' ? ' INTEGER' : ' BIGINT';
+        if ($data['type'] === TableSchema::TYPE_INTEGER || $data['type'] === TableSchema::TYPE_BIGINTEGER) {
+            $type = $data['type'] === TableSchema::TYPE_INTEGER ? ' INTEGER' : ' BIGINT';
             if ([$name] === $schema->primaryKey() || $data['autoIncrement'] === true) {
-                $type = $data['type'] === 'integer' ? ' SERIAL' : ' BIGSERIAL';
+                $type = $data['type'] === TableSchema::TYPE_INTEGER ? ' SERIAL' : ' BIGSERIAL';
                 unset($data['null'], $data['default']);
             }
             $out .= $type;
         }
 
-        if ($data['type'] === 'text' && $data['length'] !== TableSchema::LENGTH_TINY) {
+        if ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] !== TableSchema::LENGTH_TINY) {
             $out .= ' TEXT';
         }
 
-        if ($data['type'] === 'string' || ($data['type'] === 'text' && $data['length'] === TableSchema::LENGTH_TINY)) {
+        if ($data['type'] === TableSchema::TYPE_STRING ||
+            ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === TableSchema::LENGTH_TINY)
+        ) {
             $isFixed = !empty($data['fixed']);
             $type = ' VARCHAR';
             if ($isFixed) {
@@ -394,16 +397,16 @@ class PostgresSchema extends BaseSchema
             }
         }
 
-        $hasCollate = ['text', 'string'];
+        $hasCollate = [TableSchema::TYPE_TEXT, TableSchema::TYPE_STRING];
         if (in_array($data['type'], $hasCollate, true) && isset($data['collate']) && $data['collate'] !== '') {
             $out .= ' COLLATE "' . $data['collate'] . '"';
         }
 
-        if ($data['type'] === 'float' && isset($data['precision'])) {
+        if ($data['type'] === TableSchema::TYPE_FLOAT && isset($data['precision'])) {
             $out .= '(' . (int)$data['precision'] . ')';
         }
 
-        if ($data['type'] === 'decimal' &&
+        if ($data['type'] === TableSchema::TYPE_DECIMAL &&
             (isset($data['length']) || isset($data['precision']))
         ) {
             $out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
@@ -414,8 +417,9 @@ class PostgresSchema extends BaseSchema
         }
 
         if (isset($data['default']) &&
-            in_array($data['type'], ['timestamp', 'datetime']) &&
-            strtolower($data['default']) === 'current_timestamp') {
+            in_array($data['type'], [TableSchema::TYPE_TIMESTAMP, TableSchema::TYPE_DATETIME]) &&
+            strtolower($data['default']) === 'current_timestamp'
+        ) {
             $out .= ' DEFAULT CURRENT_TIMESTAMP';
         } elseif (isset($data['default'])) {
             $defaultValue = $data['default'];

+ 49 - 35
src/Database/Schema/SqliteSchema.php

@@ -15,6 +15,7 @@
 namespace Cake\Database\Schema;
 
 use Cake\Database\Exception;
+use Cake\Database\Schema\TableSchema;
 
 /**
  * Schema management/reflection features for Sqlite
@@ -66,46 +67,46 @@ class SqliteSchema extends BaseSchema
         }
 
         if ($col === 'bigint') {
-            return ['type' => 'biginteger', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_BIGINTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if ($col == 'smallint') {
-            return ['type' => 'smallinteger', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_SMALLINTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if ($col == 'tinyint') {
-            return ['type' => 'tinyinteger', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_TINYINTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if (strpos($col, 'int') !== false) {
-            return ['type' => 'integer', 'length' => $length, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_INTEGER, 'length' => $length, 'unsigned' => $unsigned];
         }
         if (strpos($col, 'decimal') !== false) {
-            return ['type' => 'decimal', 'length' => null, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_DECIMAL, 'length' => null, 'unsigned' => $unsigned];
         }
         if (in_array($col, ['float', 'real', 'double'])) {
-            return ['type' => 'float', 'length' => null, 'unsigned' => $unsigned];
+            return ['type' => TableSchema::TYPE_FLOAT, 'length' => null, 'unsigned' => $unsigned];
         }
 
         if (strpos($col, 'boolean') !== false) {
-            return ['type' => 'boolean', 'length' => null];
+            return ['type' => TableSchema::TYPE_BOOLEAN, 'length' => null];
         }
 
         if ($col === 'char' && $length === 36) {
-            return ['type' => 'uuid', 'length' => null];
+            return ['type' => TableSchema::TYPE_UUID, 'length' => null];
         }
         if ($col === 'char') {
-            return ['type' => 'string', 'fixed' => true, 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'fixed' => true, 'length' => $length];
         }
         if (strpos($col, 'char') !== false) {
-            return ['type' => 'string', 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'length' => $length];
         }
 
         if (in_array($col, ['blob', 'clob'])) {
-            return ['type' => 'binary', 'length' => null];
+            return ['type' => TableSchema::TYPE_BINARY, 'length' => null];
         }
         if (in_array($col, ['date', 'time', 'timestamp', 'datetime'])) {
             return ['type' => $col, 'length' => null];
         }
 
-        return ['type' => 'text', 'length' => null];
+        return ['type' => TableSchema::TYPE_TEXT, 'length' => null];
     }
 
     /**
@@ -283,29 +284,36 @@ class SqliteSchema extends BaseSchema
     {
         $data = $schema->column($name);
         $typeMap = [
-            'uuid' => ' CHAR(36)',
-            'smallinteger' => ' SMALLINT',
-            'tinyinteger' => ' TINYINT',
-            'integer' => ' INTEGER',
-            'biginteger' => ' BIGINT',
-            'boolean' => ' BOOLEAN',
-            'binary' => ' BLOB',
-            'float' => ' FLOAT',
-            'decimal' => ' DECIMAL',
-            'date' => ' DATE',
-            'time' => ' TIME',
-            'datetime' => ' DATETIME',
-            'timestamp' => ' TIMESTAMP',
-            'json' => ' TEXT'
+            TableSchema::TYPE_UUID => ' CHAR(36)',
+            TableSchema::TYPE_TINYINTEGER => ' TINYINT',
+            TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',
+            TableSchema::TYPE_INTEGER => ' INTEGER',
+            TableSchema::TYPE_BIGINTEGER => ' BIGINT',
+            TableSchema::TYPE_BOOLEAN => ' BOOLEAN',
+            TableSchema::TYPE_BINARY => ' BLOB',
+            TableSchema::TYPE_FLOAT => ' FLOAT',
+            TableSchema::TYPE_DECIMAL => ' DECIMAL',
+            TableSchema::TYPE_DATE => ' DATE',
+            TableSchema::TYPE_TIME => ' TIME',
+            TableSchema::TYPE_DATETIME => ' DATETIME',
+            TableSchema::TYPE_TIMESTAMP => ' TIMESTAMP',
+            TableSchema::TYPE_JSON => ' TEXT'
         ];
 
         $out = $this->_driver->quoteIdentifier($name);
-        $hasUnsigned = ['smallinteger', 'tinyinteger', 'biginteger', 'integer', 'float', 'decimal'];
+        $hasUnsigned = [
+            TableSchema::TYPE_TINYINTEGER,
+            TableSchema::TYPE_SMALLINTEGER,
+            TableSchema::TYPE_INTEGER,
+            TableSchema::TYPE_BIGINTEGER,
+            TableSchema::TYPE_FLOAT,
+            TableSchema::TYPE_DECIMAL
+        ];
 
         if (in_array($data['type'], $hasUnsigned, true) &&
             isset($data['unsigned']) && $data['unsigned'] === true
         ) {
-            if ($data['type'] !== 'integer' || [$name] !== (array)$schema->primaryKey()) {
+            if ($data['type'] !== TableSchema::TYPE_INTEGER || [$name] !== (array)$schema->primaryKey()) {
                 $out .= ' UNSIGNED';
             }
         }
@@ -314,11 +322,13 @@ class SqliteSchema extends BaseSchema
             $out .= $typeMap[$data['type']];
         }
 
-        if ($data['type'] === 'text' && $data['length'] !== TableSchema::LENGTH_TINY) {
+        if ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] !== TableSchema::LENGTH_TINY) {
             $out .= ' TEXT';
         }
 
-        if ($data['type'] === 'string' || ($data['type'] === 'text' && $data['length'] === TableSchema::LENGTH_TINY)) {
+        if ($data['type'] === TableSchema::TYPE_STRING ||
+            ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === TableSchema::LENGTH_TINY)
+        ) {
             $out .= ' VARCHAR';
 
             if (isset($data['length'])) {
@@ -326,14 +336,18 @@ class SqliteSchema extends BaseSchema
             }
         }
 
-        $integerTypes = ['integer', 'smallinteger', 'tinyinteger'];
+        $integerTypes = [
+            TableSchema::TYPE_TINYINTEGER,
+            TableSchema::TYPE_SMALLINTEGER,
+            TableSchema::TYPE_INTEGER,
+        ];
         if (in_array($data['type'], $integerTypes, true) &&
             isset($data['length']) && [$name] !== (array)$schema->primaryKey()
         ) {
                 $out .= '(' . (int)$data['length'] . ')';
         }
 
-        $hasPrecision = ['float', 'decimal'];
+        $hasPrecision = [TableSchema::TYPE_FLOAT, TableSchema::TYPE_DECIMAL];
         if (in_array($data['type'], $hasPrecision, true) &&
             (isset($data['length']) || isset($data['precision']))
         ) {
@@ -344,11 +358,11 @@ class SqliteSchema extends BaseSchema
             $out .= ' NOT NULL';
         }
 
-        if ($data['type'] === 'integer' && [$name] === (array)$schema->primaryKey()) {
+        if ($data['type'] === TableSchema::TYPE_INTEGER && [$name] === (array)$schema->primaryKey()) {
             $out .= ' PRIMARY KEY AUTOINCREMENT';
         }
 
-        if (isset($data['null']) && $data['null'] === true && $data['type'] === 'timestamp') {
+        if (isset($data['null']) && $data['null'] === true && $data['type'] === TableSchema::TYPE_TIMESTAMP) {
             $out .= ' DEFAULT NULL';
         }
         if (isset($data['default'])) {
@@ -370,7 +384,7 @@ class SqliteSchema extends BaseSchema
         $data = $schema->constraint($name);
         if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY &&
             count($data['columns']) === 1 &&
-            $schema->column($data['columns'][0])['type'] === 'integer'
+            $schema->column($data['columns'][0])['type'] === TableSchema::TYPE_INTEGER
         ) {
             return '';
         }

+ 41 - 38
src/Database/Schema/SqlserverSchema.php

@@ -85,60 +85,60 @@ class SqlserverSchema extends BaseSchema
             return ['type' => $col, 'length' => null];
         }
         if (strpos($col, 'datetime') !== false) {
-            return ['type' => 'timestamp', 'length' => null];
+            return ['type' => TableSchema::TYPE_TIMESTAMP, 'length' => null];
         }
 
         if ($col === 'tinyint') {
-            return ['type' => 'tinyinteger', 'length' => $precision ?: 3];
+            return ['type' => TableSchema::TYPE_TINYINTEGER, 'length' => $precision ?: 3];
         }
         if ($col === 'smallint') {
-            return ['type' => 'smallinteger', 'length' => $precision ?: 5];
+            return ['type' => TableSchema::TYPE_SMALLINTEGER, 'length' => $precision ?: 5];
         }
         if ($col === 'int' || $col === 'integer') {
-            return ['type' => 'integer', 'length' => $precision ?: 10];
+            return ['type' => TableSchema::TYPE_INTEGER, 'length' => $precision ?: 10];
         }
         if ($col === 'bigint') {
-            return ['type' => 'biginteger', 'length' => $precision ?: 20];
+            return ['type' => TableSchema::TYPE_BIGINTEGER, 'length' => $precision ?: 20];
         }
         if ($col === 'bit') {
-            return ['type' => 'boolean', 'length' => null];
+            return ['type' => TableSchema::TYPE_BOOLEAN, 'length' => null];
         }
         if (strpos($col, 'numeric') !== false ||
             strpos($col, 'money') !== false ||
             strpos($col, 'decimal') !== false
         ) {
-            return ['type' => 'decimal', 'length' => $precision, 'precision' => $scale];
+            return ['type' => TableSchema::TYPE_DECIMAL, 'length' => $precision, 'precision' => $scale];
         }
 
         if ($col === 'real' || $col === 'float') {
-            return ['type' => 'float', 'length' => null];
+            return ['type' => TableSchema::TYPE_FLOAT, 'length' => null];
         }
 
         if (strpos($col, 'varchar') !== false && $length < 0) {
-            return ['type' => 'text', 'length' => null];
+            return ['type' => TableSchema::TYPE_TEXT, 'length' => null];
         }
 
         if (strpos($col, 'varchar') !== false) {
-            return ['type' => 'string', 'length' => $length ?: 255];
+            return ['type' => TableSchema::TYPE_STRING, 'length' => $length ?: 255];
         }
 
         if (strpos($col, 'char') !== false) {
-            return ['type' => 'string', 'fixed' => true, 'length' => $length];
+            return ['type' => TableSchema::TYPE_STRING, 'fixed' => true, 'length' => $length];
         }
 
         if (strpos($col, 'text') !== false) {
-            return ['type' => 'text', 'length' => null];
+            return ['type' => TableSchema::TYPE_TEXT, 'length' => null];
         }
 
         if ($col === 'image' || strpos($col, 'binary')) {
-            return ['type' => 'binary', 'length' => null];
+            return ['type' => TableSchema::TYPE_BINARY, 'length' => null];
         }
 
         if ($col === 'uniqueidentifier') {
-            return ['type' => 'uuid'];
+            return ['type' => TableSchema::TYPE_UUID];
         }
 
-        return ['type' => 'string', 'length' => null];
+        return ['type' => TableSchema::TYPE_STRING, 'length' => null];
     }
 
     /**
@@ -158,7 +158,7 @@ class SqlserverSchema extends BaseSchema
         if (!empty($row['autoincrement'])) {
             $field['autoIncrement'] = true;
         }
-        if ($field['type'] === 'boolean') {
+        if ($field['type'] === TableSchema::TYPE_BOOLEAN) {
             $row['default'] = (int)$row['default'];
         }
 
@@ -331,37 +331,37 @@ class SqlserverSchema extends BaseSchema
         $data = $schema->column($name);
         $out = $this->_driver->quoteIdentifier($name);
         $typeMap = [
-            'tinyinteger' => ' TINYINT',
-            'smallinteger' => ' SMALLINT',
-            'integer' => ' INTEGER',
-            'biginteger' => ' BIGINT',
-            'boolean' => ' BIT',
-            'float' => ' FLOAT',
-            'decimal' => ' DECIMAL',
-            'date' => ' DATE',
-            'time' => ' TIME',
-            'datetime' => ' DATETIME',
-            'timestamp' => ' DATETIME',
-            'uuid' => ' UNIQUEIDENTIFIER',
-            'json' => ' NVARCHAR(MAX)',
+            TableSchema::TYPE_TINYINTEGER => ' TINYINT',
+            TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',
+            TableSchema::TYPE_INTEGER => ' INTEGER',
+            TableSchema::TYPE_BIGINTEGER => ' BIGINT',
+            TableSchema::TYPE_BOOLEAN => ' BIT',
+            TableSchema::TYPE_FLOAT => ' FLOAT',
+            TableSchema::TYPE_DECIMAL => ' DECIMAL',
+            TableSchema::TYPE_DATE => ' DATE',
+            TableSchema::TYPE_TIME => ' TIME',
+            TableSchema::TYPE_DATETIME => ' DATETIME',
+            TableSchema::TYPE_TIMESTAMP => ' DATETIME',
+            TableSchema::TYPE_UUID => ' UNIQUEIDENTIFIER',
+            TableSchema::TYPE_JSON => ' NVARCHAR(MAX)',
         ];
 
         if (isset($typeMap[$data['type']])) {
             $out .= $typeMap[$data['type']];
         }
 
-        if ($data['type'] === 'integer' || $data['type'] === 'biginteger') {
+        if ($data['type'] === TableSchema::TYPE_INTEGER || $data['type'] === TableSchema::TYPE_BIGINTEGER) {
             if ([$name] === $schema->primaryKey() || $data['autoIncrement'] === true) {
                 unset($data['null'], $data['default']);
                 $out .= ' IDENTITY(1, 1)';
             }
         }
 
-        if ($data['type'] === 'text' && $data['length'] !== Table::LENGTH_TINY) {
+        if ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] !== Table::LENGTH_TINY) {
             $out .= ' NVARCHAR(MAX)';
         }
 
-        if ($data['type'] === 'binary') {
+        if ($data['type'] === TableSchema::TYPE_BINARY) {
             $out .= ' VARBINARY';
 
             if ($data['length'] !== Table::LENGTH_TINY) {
@@ -371,7 +371,9 @@ class SqlserverSchema extends BaseSchema
             }
         }
 
-        if ($data['type'] === 'string' || ($data['type'] === 'text' && $data['length'] === Table::LENGTH_TINY)) {
+        if ($data['type'] === TableSchema::TYPE_STRING ||
+            ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === Table::LENGTH_TINY)
+        ) {
             $type = ' NVARCHAR';
 
             if (!empty($data['fixed'])) {
@@ -385,16 +387,16 @@ class SqlserverSchema extends BaseSchema
             $out .= sprintf('%s(%d)', $type, $data['length']);
         }
 
-        $hasCollate = ['text', 'string'];
+        $hasCollate = [TableSchema::TYPE_TEXT, TableSchema::TYPE_STRING];
         if (in_array($data['type'], $hasCollate, true) && isset($data['collate']) && $data['collate'] !== '') {
             $out .= ' COLLATE ' . $data['collate'];
         }
 
-        if ($data['type'] === 'float' && isset($data['precision'])) {
+        if ($data['type'] === TableSchema::TYPE_FLOAT && isset($data['precision'])) {
             $out .= '(' . (int)$data['precision'] . ')';
         }
 
-        if ($data['type'] === 'decimal' &&
+        if ($data['type'] === TableSchema::TYPE_DECIMAL &&
             (isset($data['length']) || isset($data['precision']))
         ) {
             $out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
@@ -405,8 +407,9 @@ class SqlserverSchema extends BaseSchema
         }
 
         if (isset($data['default']) &&
-            in_array($data['type'], ['timestamp', 'datetime']) &&
-            strtolower($data['default']) === 'current_timestamp') {
+            in_array($data['type'], [TableSchema::TYPE_TIMESTAMP, TableSchema::TYPE_DATETIME]) &&
+            strtolower($data['default']) === 'current_timestamp'
+        ) {
             $out .= ' DEFAULT CURRENT_TIMESTAMP';
         } elseif (isset($data['default'])) {
             $default = is_bool($data['default']) ? (int)$data['default'] : $this->_driver->schemaValue($data['default']);

+ 112 - 0
src/Database/Schema/TableSchema.php

@@ -249,6 +249,118 @@ class TableSchema
     const INDEX_FULLTEXT = 'fulltext';
 
     /**
+     * Binary column type
+     *
+     * @var string
+     */
+    const TYPE_BINARY = 'binary';
+
+    /**
+     * Date column type
+     *
+     * @var string
+     */
+    const TYPE_DATE = 'date';
+
+    /**
+     * Datetime column type
+     *
+     * @var string
+     */
+    const TYPE_DATETIME = 'datetime';
+
+    /**
+     * Time column type
+     *
+     * @var string
+     */
+    const TYPE_TIME = 'time';
+
+    /**
+     * Timestamp column type
+     *
+     * @var string
+     */
+    const TYPE_TIMESTAMP = 'timestamp';
+
+    /**
+     * JSON column type
+     *
+     * @var string
+     */
+    const TYPE_JSON = 'json';
+
+    /**
+     * String column type
+     *
+     * @var string
+     */
+    const TYPE_STRING = 'string';
+
+    /**
+     * Text column type
+     *
+     * @var string
+     */
+    const TYPE_TEXT = 'text';
+
+    /**
+     * Tiny Integer column type
+     *
+     * @var string
+     */
+    const TYPE_TINYINTEGER = 'tinyinteger';
+
+    /**
+     * Small Integer column type
+     *
+     * @var string
+     */
+    const TYPE_SMALLINTEGER = 'smallinteger';
+
+    /**
+     * Integer column type
+     *
+     * @var string
+     */
+    const TYPE_INTEGER = 'integer';
+
+    /**
+     * Big Integer column type
+     *
+     * @var string
+     */
+    const TYPE_BIGINTEGER = 'biginteger';
+
+    /**
+     * Float column type
+     *
+     * @var string
+     */
+    const TYPE_FLOAT = 'float';
+
+    /**
+     * Decimal column type
+     *
+     * @var string
+     */
+    const TYPE_DECIMAL = 'decimal';
+
+    /**
+     * Boolean column type
+     *
+     * @var string
+     */
+    const TYPE_BOOLEAN = 'boolean';
+
+    /**
+     * UUID column type
+     *
+     * @var string
+     */
+    const TYPE_UUID = 'uuid';
+
+    /**
      * Foreign key cascade action
      *
      * @var string