Browse Source

Add binaryuuid reflection/generation to Mysql schema.

Mark Story 8 years ago
parent
commit
58e26c01f9

+ 4 - 0
src/Database/Schema/MysqlSchema.php

@@ -134,6 +134,9 @@ class MysqlSchema extends BaseSchema
 
             return ['type' => TableSchema::TYPE_TEXT, 'length' => $length];
         }
+        if ($col === 'binary' && $length === 16) {
+            return ['type' => TableSchema::TYPE_BINARY_UUID, 'length' => null];
+        }
         if (strpos($col, 'blob') !== false || $col === 'binary') {
             $lengthName = substr($col, 0, -4);
             $length = isset(Table::$columnLengths[$lengthName]) ? Table::$columnLengths[$lengthName] : null;
@@ -314,6 +317,7 @@ class MysqlSchema extends BaseSchema
             TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',
             TableSchema::TYPE_INTEGER => ' INTEGER',
             TableSchema::TYPE_BIGINTEGER => ' BIGINT',
+            TableSchema::TYPE_BINARY_UUID => ' BINARY(16)',
             TableSchema::TYPE_BOOLEAN => ' BOOLEAN',
             TableSchema::TYPE_FLOAT => ' FLOAT',
             TableSchema::TYPE_DECIMAL => ' DECIMAL',

+ 9 - 0
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -120,6 +120,10 @@ class MysqlSchemaTest extends TestCase
                 ['type' => 'uuid', 'length' => null]
             ],
             [
+                'BINARY(16)',
+                ['type' => 'binaryuuid', 'length' => null]
+            ],
+            [
                 'TEXT',
                 ['type' => 'text', 'length' => null]
             ],
@@ -531,6 +535,11 @@ SQL;
                 '`id` CHAR(36)'
             ],
             [
+                'id',
+                ['type' => 'binaryuuid'],
+                '`id` BINARY(16)'
+            ],
+            [
                 'title',
                 ['type' => 'string', 'length' => 255, 'null' => false, 'collate' => 'utf8_unicode_ci'],
                 '`title` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL'