aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-01-30 12:42:39 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-01-30 12:42:39 -0500
commita398cd0bcbd39998f1b0313e6fe3f04bf491b3db (patch)
tree22a870ae5a0ffb0acdbbe24eba1e51642840b901
parenta59212709c1daddf1c3703198cc3e45fd5226baf (diff)
downloadrails-a398cd0bcbd39998f1b0313e6fe3f04bf491b3db.tar.gz
rails-a398cd0bcbd39998f1b0313e6fe3f04bf491b3db.tar.bz2
rails-a398cd0bcbd39998f1b0313e6fe3f04bf491b3db.zip
Revert "Merge pull request #23346 from kamipo/refactor_oid_money_precision"
This reverts commit ff835f90800a3e4122d64606cb328908c2e0e071, reversing changes made to c4d85dfbc71043e2a746acd310e32f4f04db801a. Reason: This broke the tests. We will add back after investigated.
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb8
2 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
index 78039b719c..2163674019 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
@@ -3,14 +3,12 @@ module ActiveRecord
module PostgreSQL
module OID # :nodoc:
class Money < Type::Decimal # :nodoc:
+ class_attribute :precision
+
def type
:money
end
- def precision
- 19
- end
-
def scale
2
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 725173d995..2de6fbfaf0 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -213,7 +213,7 @@ module ActiveRecord
@statements = StatementPool.new @connection,
self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 })
- if postgresql_version < 80300
+ if postgresql_version < 80200
raise "Your version of PostgreSQL (#{postgresql_version}) is too old, please upgrade!"
end
@@ -645,6 +645,12 @@ module ActiveRecord
# connected server's characteristics.
def connect
@connection = PGconn.connect(@connection_parameters)
+
+ # Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
+ # PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
+ # should know about this but can't detect it there, so deal with it here.
+ OID::Money.precision = (postgresql_version >= 80300) ? 19 : 10
+
configure_connection
rescue ::PG::Error => error
if error.message.include?("does not exist")