Skip to content
Permalink
Browse files

Postgres' money type should be handled as a string.

The money type contains effectively arbitrary string content before the
numbers. Treating this data as a float results in 0.0 for all amounts
which is annoying. By handling this type as a string we can give the
developer the data they would see in pgadmin.

Refs #6193
  • Loading branch information...
markstory committed Apr 4, 2015
1 parent 9eeb4dc commit 778c80f9e1656852dcf0d6f635c8f612beea78e5
Showing with 9 additions and 6 deletions.
  1. +5 −2 src/Database/Schema/PostgresSchema.php
  2. +4 −4 tests/TestCase/Database/Schema/PostgresSchemaTest.php
@@ -103,7 +103,11 @@ protected function _convertColumn($column)
if ($col === 'char' || $col === 'character') {
return ['type' => 'string', 'fixed' => true, 'length' => $length];
}
if (strpos($col, 'char') !== false) {
// money is 'string' as it includes arbitrary text content
// before the number value.
if (strpos($col, 'char') !== false ||
strpos($col, 'money') !== false
) {
return ['type' => 'string', 'length' => $length];
}
if (strpos($col, 'text') !== false) {
@@ -116,7 +120,6 @@ protected function _convertColumn($column)
return ['type' => 'float', 'length' => null];
}
if (strpos($col, 'numeric') !== false ||
strpos($col, 'money') !== false ||
strpos($col, 'decimal') !== false
) {
return ['type' => 'decimal', 'length' => null];
@@ -138,10 +138,6 @@ public static function convertColumnProvider()
'DECIMAL(10,2)',
['type' => 'decimal', 'length' => null]
],
[
'MONEY',
['type' => 'decimal', 'length' => null]
],
// String
[
'VARCHAR',
@@ -167,6 +163,10 @@ public static function convertColumnProvider()
'CHARACTER(10)',
['type' => 'string', 'fixed' => true, 'length' => 10]
],
[
'MONEY',
['type' => 'string', 'length' => null]
],
// UUID
[
'UUID',

0 comments on commit 778c80f

Please sign in to comment.
You can’t perform that action at this time.