Skip to content
Browse files

Merge pull request #14791 from asn62/mysql_double_bug

Changed extract_limit in class Column to return correct mysql float and
double limits
  • Loading branch information...
2 parents 2367dfe + 51de8ce commit 1ad4b489919a679f29a3bc5a331542bd26e5b5a6 @matthewd matthewd committed May 16, 2014
View
7 activerecord/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Floats with limit >= 25 that get turned into doubles in MySQL no longer have
+ their limit dropped from the schema.
+
+ Fixes #14135.
+
+ *Aaron Nelson*
+
* Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many`
association.
View
2 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -129,6 +129,8 @@ def extract_limit(sql_type)
when /^mediumint/i; 3
when /^smallint/i; 2
when /^tinyint/i; 1
+ when /^float/i; 24
+ when /^double/i; 53
else
super
end
View
38 activerecord/test/cases/adapters/mysql/schema_test.rb
@@ -17,6 +17,44 @@ def setup
self.table_name = "#{db}.#{table}"
def self.name; 'Post'; end
end
+
+ @connection.create_table "mysql_doubles"
+ end
+
+ teardown do
+ @connection.execute "drop table if exists mysql_doubles"
+ end
+
+ class MysqlDouble < ActiveRecord::Base
+ self.table_name = "mysql_doubles"
+ end
+
+ def test_float_limits
+ @connection.add_column :mysql_doubles, :float_no_limit, :float
+ @connection.add_column :mysql_doubles, :float_short, :float, limit: 5
+ @connection.add_column :mysql_doubles, :float_long, :float, limit: 53
+
+ @connection.add_column :mysql_doubles, :float_23, :float, limit: 23
+ @connection.add_column :mysql_doubles, :float_24, :float, limit: 24
+ @connection.add_column :mysql_doubles, :float_25, :float, limit: 25
+ MysqlDouble.reset_column_information
+
+ column_no_limit = MysqlDouble.columns.find { |c| c.name == 'float_no_limit' }
+ column_short = MysqlDouble.columns.find { |c| c.name == 'float_short' }
+ column_long = MysqlDouble.columns.find { |c| c.name == 'float_long' }
+
+ column_23 = MysqlDouble.columns.find { |c| c.name == 'float_23' }
+ column_24 = MysqlDouble.columns.find { |c| c.name == 'float_24' }
+ column_25 = MysqlDouble.columns.find { |c| c.name == 'float_25' }
+
+ # Mysql floats are precision 0..24, Mysql doubles are precision 25..53
+ assert_equal 24, column_no_limit.limit
+ assert_equal 24, column_short.limit
+ assert_equal 53, column_long.limit
+
+ assert_equal 24, column_23.limit
+ assert_equal 24, column_24.limit
+ assert_equal 53, column_25.limit
end
def test_schema

0 comments on commit 1ad4b48

Please sign in to comment.
Something went wrong with that request. Please try again.