public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added that the MySQL adapter should map integer to either smallint, int, or 
bigint depending on the :limit just like PostgreSQL [DHH]
David Heinemeier Hansson (author)
Fri Apr 25 14:33:00 -0700 2008
commit  a37546517dad9f6d9a7de6e1dba4d960909d71e8
tree    a96de198754909ac7fb131e4eee49adf6189b2d3
parent  1959db324653d5db345b935c9d2696c544d836af
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added that the MySQL adapter should map integer to either smallint, int, or bigint depending on the :limit just like PostgreSQL [DHH]
0
+
0
 * Change validates_uniqueness_of :case_sensitive option default back to true (from [9160]).  Love your database columns, don't LOWER them.  [rick]
0
 
0
 * Add support for interleaving migrations by storing which migrations have run in the new schema_migrations table. Closes #11493 [jordi]
...
463
464
465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
467
468
...
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
0
@@ -463,6 +463,22 @@ module ActiveRecord
0
         execute "ALTER TABLE #{quote_table_name(table_name)} CHANGE #{quote_column_name(column_name)} #{quote_column_name(new_column_name)} #{current_type}"
0
       end
0
 
0
+      # Maps logical Rails types to MySQL-specific data types.
0
+      def type_to_sql(type, limit = nil, precision = nil, scale = nil)
0
+        return super unless type.to_s == 'integer'
0
+
0
+        case limit
0
+        when 0..3
0
+          "smallint(#{limit})"
0
+        when 4..8
0
+          "int(#{limit})"
0
+        when 9..20
0
+          "bigint(#{limit})"
0
+        else
0
+          'int(11)'
0
+        end
0
+      end
0
+
0
 
0
       # SHOW VARIABLES LIKE 'name'
0
       def show_variable(name)

Comments

matthuhiggins Sat Apr 26 22:42:36 -0700 2008

I would replace: :integer => { :name => “int”}, :limit => 11 },

with: :integer => { :name => “int”},

Otherwise, the default case of ‘int(11)’ is never executed.

digitalhobbit Wed May 21 15:01:23 -0700 2008

Even with that change, this is causing problems when cloning the test database, as integer columns that were originally specified without an explicit limit in the migration now have a limit of 11, resulting in them being created as bigint(11) rather than int(11). This in turn breaks the clone when using foreign key constraints.

See [#55] for more details.

barbarycodes Mon Jun 16 09:54:29 -0700 2008

This patch is not backwards compatible in general. The default for :integer was int(11), so the new range for “integer” should include 11 (see my meta-patch at http://timothynjones.wordpress.com/2008/06/10/change-to-activerecord-mysql-adapter-breaks-tests/).>

tarmo Mon Jun 16 13:02:46 -0700 2008

timothynjones, this code is actually going to chance once more with: http://rails.lighthouseapp.com/projects/8994/tickets/420-interpret-limit-as-number-of-bytes

And the :limit is no longer going to specify the number of decimal places, instead if will specify the number of bytes, so I’d suggest not at all adding a :limit option to your integers unless you need bigint or mediumint or smallint. For schema.rb there should be no compatibility problems as I believe schema.rb has never dumped :limit for :integer types (rather the change would actually make schema.rb more accurate in being able to create correct integer types where it used to always create 4 byte integers).