Browse Source

Fix MySQL schema generation for float types.

Schema generation can now create float(x) columns with only
length and no precision defined.

Merge branch 'issue-13700' into master
Mark Story 6 years ago
parent
commit
37acb61bd9

+ 1 - 0
.gitignore

@@ -7,6 +7,7 @@
 /phpunit.xml
 /phpcs.xml
 /vendor
+/vendors
 /composer.phar
 *.mo
 debug.log

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

@@ -389,10 +389,12 @@ class MysqlSchema extends BaseSchema
         }
 
         $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'] . ')';
+        if (in_array($data['type'], $hasPrecision, true) && isset($data['length'])) {
+            if (isset($data['precision'])) {
+                $out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
+            } else {
+                $out .= '(' . (int)$data['length'] . ')';
+            }
         }
 
         $hasUnsigned = [

+ 6 - 1
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -670,7 +670,7 @@ SQL;
             [
                 'value',
                 ['type' => 'decimal', 'length' => 11, 'unsigned' => true],
-                '`value` DECIMAL(11,0) UNSIGNED'
+                '`value` DECIMAL(11) UNSIGNED'
             ],
             [
                 'value',
@@ -689,6 +689,11 @@ SQL;
                 '`value` FLOAT UNSIGNED'
             ],
             [
+                'latitude',
+                ['type' => 'float', 'length' => 53, 'null' => true, 'default' => null, 'unsigned' => true],
+                '`latitude` FLOAT(53) UNSIGNED',
+            ],
+            [
                 'value',
                 ['type' => 'float', 'length' => 11, 'precision' => 3],
                 '`value` FLOAT(11,3)'