Skip to content

Commit

Permalink
Postgres' money type should be handled as a string.
Browse files Browse the repository at this point in the history
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 778c80f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/Database/Schema/PostgresSchema.php
Expand Up @@ -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) {
Expand All @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Database/Schema/PostgresSchemaTest.php
Expand Up @@ -138,10 +138,6 @@ public static function convertColumnProvider()
'DECIMAL(10,2)',
['type' => 'decimal', 'length' => null]
],
[
'MONEY',
['type' => 'decimal', 'length' => null]
],
// String
[
'VARCHAR',
Expand All @@ -167,6 +163,10 @@ public static function convertColumnProvider()
'CHARACTER(10)',
['type' => 'string', 'fixed' => true, 'length' => 10]
],
[
'MONEY',
['type' => 'string', 'length' => null]
],
// UUID
[
'UUID',
Expand Down

0 comments on commit 778c80f

Please sign in to comment.