Change to ActiveRecord MySQL adapter breaks tests

By timothynjones

This patch: http://github.com/rails/rails/commit/a37546517dad9f6d9a7de6e1dba4d960909d71e8
means that test database structure is not created properly (integer columns get recreated as bigints).  If you’re also using Foreign Key Migrations, your test database simply won’t get built.  It’s too bad the Rails core team didn’t more carefully consider the implications of this patch.  Anyway, we can correct the mistake with the following patch:

===================================================================
--- vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb	(revision 62)
+++ vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb	(working copy)
@@ -470,9 +470,9 @@
         case limit
         when 0..3
           "smallint(#{limit})"
-        when 4..8
+        when 4..11
           "int(#{limit})"
-        when 9..20
+        when 12..20
           "bigint(#{limit})"
         else
           'int(11)'

4 Responses to “Change to ActiveRecord MySQL adapter breaks tests”

  1. Blake Says:

    Did you try posting a comment on the URL for the commit? I’m curious how that works on GitHub and whether people read them (seems like a reasonably low-friction way to do code reviews).

  2. timothynjones Says:

    I just posted a comment, so we shall see…

  3. John Trupiano Says:

    I found this to be useful….I’ll re-blogged it here: http://blog.smartlogicsolutions.com/2008/06/24/rails-21-broke-my-mysql-foreign-keys/. Thanks Tim!

  4. SmartLogic Solutions Blog » Blog Archive » Rails 2.1 broke my mysql foreign keys! Says:

    [...] Mirko Froehlich suggests monkey patching this function. Timothy Jones blogged about it. [...]

Leave a Reply