From 0272e443f44ebca55b05c14f2a112260ff0df284 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 2 Nov 2015 13:59:45 +1300 Subject: [PATCH] BUG Prevent dev/build continually regenerating Number field type --- model/connect/MySQLSchemaManager.php | 8 +++++--- tests/model/DataObjectSchemaGenerationTest.php | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/model/connect/MySQLSchemaManager.php b/model/connect/MySQLSchemaManager.php index 85157de58..3fc9d59db 100644 --- a/model/connect/MySQLSchemaManager.php +++ b/model/connect/MySQLSchemaManager.php @@ -407,15 +407,17 @@ class MySQLSchemaManager extends DBSchemaManager { $precision = $values['precision']; } - $defaultValue = ''; + // Fix format of default value to match precision if (isset($values['default']) && is_numeric($values['default'])) { $decs = strpos($precision, ',') !== false ? (int) substr($precision, strpos($precision, ',') + 1) : 0; - $defaultValue = ' default ' . number_format($values['default'], $decs, '.', ''); + $values['default'] = number_format($values['default'], $decs, '.', ''); + } else { + unset($values['default']); } - return "decimal($precision) not null $defaultValue"; + return "decimal($precision) not null" . $this->defaultClause($values); } /** diff --git a/tests/model/DataObjectSchemaGenerationTest.php b/tests/model/DataObjectSchemaGenerationTest.php index 7c4b80dfe..e772b4184 100644 --- a/tests/model/DataObjectSchemaGenerationTest.php +++ b/tests/model/DataObjectSchemaGenerationTest.php @@ -178,6 +178,11 @@ class DataObjectSchemaGenerationTest_DO extends DataObject implements TestOnly { private static $db = array( 'Enum1' => 'Enum("A, B, C, D","")', 'Enum2' => 'Enum("A, B, C, D","A")', + 'NumberField' => 'Decimal', + 'FloatingField' => 'Decimal(10,3,1.1)', + 'TextValue' => 'Varchar', + 'Date' => 'SS_Datetime', + 'MyNumber' => 'Int' ); }