From 38deb0ed83c54444e091d39382dcfe58e1c0bd05 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 25 May 2007 21:21:41 +0000 Subject: Migrations: add_column supports custom column types. Closes #7742. First-patch cheers to jsgarvin\! git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6842 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../abstract/schema_statements.rb | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index a98b26f554..2ffe3690ef 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -253,25 +253,28 @@ module ActiveRecord def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc: - native = native_database_types[type] - column_type_sql = native.is_a?(Hash) ? native[:name] : native - if type == :decimal # ignore limit, use precison and scale - precision ||= native[:precision] - scale ||= native[:scale] - if precision - if scale - column_type_sql << "(#{precision},#{scale})" + if native = native_database_types[type] + column_type_sql = native.is_a?(Hash) ? native[:name] : native + if type == :decimal # ignore limit, use precison and scale + precision ||= native[:precision] + scale ||= native[:scale] + if precision + if scale + column_type_sql << "(#{precision},#{scale})" + else + column_type_sql << "(#{precision})" + end else - column_type_sql << "(#{precision})" + raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale end + column_type_sql else - raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale + limit ||= native[:limit] + column_type_sql << "(#{limit})" if limit + column_type_sql end - column_type_sql else - limit ||= native[:limit] - column_type_sql << "(#{limit})" if limit - column_type_sql + column_type_sql = type end end -- cgit v1.2.3