Changeset 6842
- Timestamp:
- 05/25/07 21:21:41 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (modified) (1 diff)
- trunk/activerecord/test/migration_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6833 r6842 1 1 *SVN* 2 3 * Migrations: add_column supports custom column types. #7742 [jsgarvin, Theory] 2 4 3 5 * 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] trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
r5956 r6842 254 254 255 255 def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc: 256 native = native_database_types[type] 257 column_type_sql = native.is_a?(Hash) ? native[:name] : native 258 if type == :decimal # ignore limit, use precison and scale 259 precision ||= native[:precision] 260 scale ||= native[:scale] 261 if precision 262 if scale 263 column_type_sql << "(#{precision},#{scale})" 256 if native = native_database_types[type] 257 column_type_sql = native.is_a?(Hash) ? native[:name] : native 258 if type == :decimal # ignore limit, use precison and scale 259 precision ||= native[:precision] 260 scale ||= native[:scale] 261 if precision 262 if scale 263 column_type_sql << "(#{precision},#{scale})" 264 else 265 column_type_sql << "(#{precision})" 266 end 264 267 else 265 column_type_sql << "(#{precision})"268 raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale 266 269 end 270 column_type_sql 267 271 else 268 raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale 272 limit ||= native[:limit] 273 column_type_sql << "(#{limit})" if limit 274 column_type_sql 269 275 end 270 column_type_sql271 276 else 272 limit ||= native[:limit] 273 column_type_sql << "(#{limit})" if limit 274 column_type_sql 277 column_type_sql = type 275 278 end 276 279 end trunk/activerecord/test/migration_test.rb
r6756 r6842 313 313 assert_equal TrueClass, bob.male?.class 314 314 assert_kind_of BigDecimal, bob.wealth 315 end 316 317 if current_adapter?(:MysqlAdapter) 318 def test_unabstracted_database_dependent_types 319 Person.delete_all 320 321 ActiveRecord::Migration.add_column :people, :intelligence_quotient, :tinyint 322 Person.create :intelligence_quotient => 300 323 jonnyg = Person.find(:first) 324 assert_equal 127, jonnyg.intelligence_quotient 325 jonnyg.destroy 326 ensure 327 ActiveRecord::Migration.remove_column :people, :intelligece_quotient rescue nil 328 end 315 329 end 316 330