Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added that the MySQL adapter should map integer to either smallint, i…
…nt, or bigint depending on the :limit just like PostgreSQL [DHH]
- Loading branch information
David Heinemeier Hansson
committed
Apr 25, 2008
1 parent
1959db3
commit a375465
Showing
2 changed files
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a375465
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace:
:integer => { :name => "int"}, :limit => 11 },
with:
:integer => { :name => "int"},
Otherwise, the default case of ‘int(11)’ is never executed.
a375465
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
a375465
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/).
a375465
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).