Browse Source

Add smallint/tinyint types to postgres.

There is no tinyint in postgres, so we'll map it to the smallest int
possible on that platform.
Mark Story 9 years ago
parent
commit
3cafe995bd

+ 3 - 1
src/Database/Schema/PostgresSchema.php

@@ -102,7 +102,7 @@ class PostgresSchema extends BaseSchema
             return ['type' => 'biginteger', 'length' => 20];
         }
         if ($col === 'smallint') {
-            return ['type' => 'integer', 'length' => 5];
+            return ['type' => 'smallint', 'length' => 5];
         }
         if ($col === 'inet') {
             return ['type' => 'string', 'length' => 39];
@@ -351,6 +351,8 @@ class PostgresSchema extends BaseSchema
         $data = $schema->column($name);
         $out = $this->_driver->quoteIdentifier($name);
         $typeMap = [
+            'tinyint' => ' SMALLINT',
+            'smallint' => ' SMALLINT',
             'boolean' => ' BOOLEAN',
             'binary' => ' BYTEA',
             'float' => ' FLOAT',

+ 11 - 1
tests/TestCase/Database/Schema/PostgresSchemaTest.php

@@ -121,7 +121,7 @@ SQL;
             // Integer
             [
                 'SMALLINT',
-                ['type' => 'integer', 'length' => 5]
+                ['type' => 'smallint', 'length' => 5]
             ],
             [
                 'INTEGER',
@@ -709,6 +709,16 @@ SQL;
             // Integers
             [
                 'post_id',
+                ['type' => 'tinyint', 'length' => 11],
+                '"post_id" SMALLINT'
+            ],
+            [
+                'post_id',
+                ['type' => 'smallint', 'length' => 11],
+                '"post_id" SMALLINT'
+            ],
+            [
+                'post_id',
                 ['type' => 'integer', 'length' => 11],
                 '"post_id" INTEGER'
             ],