Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added better exception error when unknown column types are used with …

…migrations #1814 [fbeausoleil@ftml.net]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2201 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 57070277b420819b9bf0980e1a794a587f31dff6 1 parent ffbaf1c
David Heinemeier Hansson dhh authored
2  activerecord/CHANGELOG
View
@@ -1,5 +1,7 @@
*SVN*
+* Added better exception error when unknown column types are used with migrations #1814 [fbeausoleil@ftml.net]
+
* Fixed "connection lost" issue with the bundled Ruby/MySQL driver (would kill the app after 8 hours of inactivity) #2163, #428 [kajism@yahoo.com]
* Fixed comparison of Active Record objects so two new objects are not equal #2099 [deberg]
6 activerecord/lib/active_record/base.rb
View
@@ -28,7 +28,9 @@ class StaleObjectError < ActiveRecordError #:nodoc:
end
class ConfigurationError < StandardError #:nodoc:
end
-
+ class UnknownTypeError < ActiveRecordError #:nodoc:
+ end
+
class AttributeAssignmentError < ActiveRecordError #:nodoc:
attr_reader :exception, :attribute
def initialize(message, exception, attribute)
@@ -222,6 +224,8 @@ def initialize(errors)
# objects that should be inspected to determine which attributes triggered the errors.
# * +AttributeAssignmentError+ -- an error occurred while doing a mass assignment through the +attributes=+ method.
# You can inspect the +attribute+ property of the exception object to determine which attribute triggered the error.
+ # * +UnknownTypeError+ -- Raised when AbstractAdapter#type_to_sql cannot map the type given to a native type.
+ #
# *Note*: The attributes listed are class-level attributes (accessible from both the class and instance level).
# So it's possible to assign a logger to the class through Base.logger= which will then be used by all
# instances in the current object space.
9 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
View
@@ -431,7 +431,14 @@ def native_database_types
end
def type_to_sql(type, limit = nil)
- native = native_database_types[type]
+ unless native = native_database_types[type]
+ raise(
+ ActiveRecord::UnknownTypeError,
+ "Unable to convert type '#{type}' to a native type. " +
+ "Valid options: #{native_database_types.keys.to_sentence}"
+ )
+ end
+
limit ||= native[:limit]
column_type_sql = native[:name]
column_type_sql << "(#{limit})" if limit
14 activerecord/test/active_schema_test.rb
View
@@ -0,0 +1,14 @@
+require 'abstract_unit'
+
+class ActiveSchemaTest < Test::Unit::TestCase
+ def test_add_column_with_native_type_rejected
+ assert_raises ActiveRecord::UnknownTypeError do
+ add_column(:people, :varchar, :limit => 15)
+ end
+ end
+
+ private
+ def method_missing(method_symbol, *arguments)
+ ActiveRecord::Base.connection.send(method_symbol, *arguments)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.