diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-25 21:21:41 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-25 21:21:41 +0000 |
commit | 38deb0ed83c54444e091d39382dcfe58e1c0bd05 (patch) | |
tree | 49d74d50d9d5e82632d9593bd247cb5680333f07 | |
parent | 0cbb75e9a06fc59d8d2995389954050853d4bccc (diff) | |
download | rails-38deb0ed83c54444e091d39382dcfe58e1c0bd05.tar.gz rails-38deb0ed83c54444e091d39382dcfe58e1c0bd05.tar.bz2 rails-38deb0ed83c54444e091d39382dcfe58e1c0bd05.zip |
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
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 31 | ||||
-rw-r--r-- | activerecord/test/migration_test.rb | 14 |
3 files changed, 33 insertions, 14 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 6c174a4122..0bed07029b 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Migrations: add_column supports custom column types. #7742 [jsgarvin, Theory] + * Load database adapters on demand. Eliminates config.connection_adapters and RAILS_CONNECTION_ADAPTERS. Add your lib directory to the $LOAD_PATH and put your custom adapter in lib/active_record/connection_adapters/adaptername_adapter.rb. This way you can provide custom adapters as plugins or gems without modifying Rails. [Jeremy Kemper] * Ensure that associations with :dependent => :delete_all respect :conditions option. Closes #8034 [danger, joshpeek, Rick] 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 diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index eacff078ee..8a3c1d05ed 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -314,6 +314,20 @@ if ActiveRecord::Base.connection.supports_migrations? assert_kind_of BigDecimal, bob.wealth end + if current_adapter?(:MysqlAdapter) + def test_unabstracted_database_dependent_types + Person.delete_all + + ActiveRecord::Migration.add_column :people, :intelligence_quotient, :tinyint + Person.create :intelligence_quotient => 300 + jonnyg = Person.find(:first) + assert_equal 127, jonnyg.intelligence_quotient + jonnyg.destroy + ensure + ActiveRecord::Migration.remove_column :people, :intelligece_quotient rescue nil + end + end + def test_add_remove_single_field_using_string_arguments assert !Person.column_methods_hash.include?(:last_name) |