Skip to content

Commit 778c80f

Browse files
committed
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
1 parent 9eeb4dc commit 778c80f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Database/Schema/PostgresSchema.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ protected function _convertColumn($column)
103103
if ($col === 'char' || $col === 'character') {
104104
return ['type' => 'string', 'fixed' => true, 'length' => $length];
105105
}
106-
if (strpos($col, 'char') !== false) {
106+
// money is 'string' as it includes arbitrary text content
107+
// before the number value.
108+
if (strpos($col, 'char') !== false ||
109+
strpos($col, 'money') !== false
110+
) {
107111
return ['type' => 'string', 'length' => $length];
108112
}
109113
if (strpos($col, 'text') !== false) {
@@ -116,7 +120,6 @@ protected function _convertColumn($column)
116120
return ['type' => 'float', 'length' => null];
117121
}
118122
if (strpos($col, 'numeric') !== false ||
119-
strpos($col, 'money') !== false ||
120123
strpos($col, 'decimal') !== false
121124
) {
122125
return ['type' => 'decimal', 'length' => null];

tests/TestCase/Database/Schema/PostgresSchemaTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ public static function convertColumnProvider()
138138
'DECIMAL(10,2)',
139139
['type' => 'decimal', 'length' => null]
140140
],
141-
[
142-
'MONEY',
143-
['type' => 'decimal', 'length' => null]
144-
],
145141
// String
146142
[
147143
'VARCHAR',
@@ -167,6 +163,10 @@ public static function convertColumnProvider()
167163
'CHARACTER(10)',
168164
['type' => 'string', 'fixed' => true, 'length' => 10]
169165
],
166+
[
167+
'MONEY',
168+
['type' => 'string', 'length' => null]
169+
],
170170
// UUID
171171
[
172172
'UUID',

0 commit comments

Comments
 (0)