I'm working on a rails application that changes the behavior of nils, which causes migrations to break. One could argue that you should change that behavior of ruby, of which I completely agree, but the consequences of this app would be devestating as there are no test cases.
Anyways, the primary_key database type is depending on the fact that type_to_sql will throw an error because when it looks up native database type key "int(11) DEFAULT NULL auto_increment PRIMARY KEY" - it doesn't exist. Obviously, it's expecting something like :string.
If no error is thrown, then nil is returned as the type, rather than the entire type "int(11) DEFAULT NULL auto_increment PRIMARY KEY" - which is what makes it work.
This patch makes the function not dependent on an error being thrown for the proper over-ride to be returned.
The better solution may be to change the native_database_type primary_key column, but I'm doubting that. A even better solution may be to just leave it alone. Anyways... if it adds value at all, here's the patch.
Index: C:/www/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
===================================================================
--- C:/www/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (revision 5774)
+++ C:/www/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (working copy)
@@ -254,6 +254,7 @@
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
native = native_database_types[type]
+ return type if ! native
column_type_sql = native[:name]
if type == :decimal # ignore limit, use precison and scale
precision
= native[:precision]
Change History
Download in other formats:
|