Browse Source

Add binaryuuid reflection and generation to sqlite driver.

Mark Story 8 years ago
parent
commit
be316ac356

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

@@ -99,6 +99,9 @@ class SqliteSchema extends BaseSchema
             return ['type' => TableSchema::TYPE_STRING, 'length' => $length];
         }
 
+        if ($col === 'binary' && $length === 16) {
+            return ['type' => TableSchema::TYPE_BINARY_UUID, 'length' => null];
+        }
         if (in_array($col, ['blob', 'clob'])) {
             return ['type' => TableSchema::TYPE_BINARY, 'length' => null];
         }
@@ -284,6 +287,7 @@ class SqliteSchema extends BaseSchema
     {
         $data = $schema->getColumn($name);
         $typeMap = [
+            TableSchema::TYPE_BINARY_UUID => ' BINARY(16)',
             TableSchema::TYPE_UUID => ' CHAR(36)',
             TableSchema::TYPE_TINYINTEGER => ' TINYINT',
             TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',

+ 7 - 0
src/Database/Schema/TableSchemaInterface.php

@@ -30,6 +30,13 @@ interface TableSchemaInterface extends SchemaInterface
     const TYPE_BINARY = 'binary';
 
     /**
+     * Binary UUID column type
+     *
+     * @var string
+     */
+    const TYPE_BINARY_UUID = 'binaryuuid';
+
+    /**
      * Date column type
      *
      * @var string

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

@@ -84,6 +84,10 @@ class SqliteSchemaTest extends TestCase
                 ['type' => 'uuid', 'length' => null]
             ],
             [
+                'BINARY(16)',
+                ['type' => 'binaryuuid', 'length' => null]
+            ],
+            [
                 'BLOB',
                 ['type' => 'binary', 'length' => null]
             ],
@@ -487,6 +491,11 @@ SQL;
                 ['type' => 'uuid'],
                 '"id" CHAR(36)'
             ],
+            [
+                'id',
+                ['type' => 'binaryuuid'],
+                '"id" BINARY(16)'
+            ],
             // Text
             [
                 'body',