Changeset 8453
- Timestamp:
- 12/20/07 22:28:12 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb (modified) (3 diffs)
- trunk/activerecord/test/migration_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8439 r8453 1 1 *SVN* 2 3 * SQLite: fix rename_ and remove_column for columns with unique indexes. #10576 [Brandon Keepers] 2 4 3 5 * Ruby 1.9 compatibility. [Jeremy Kemper] trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
r8113 r8453 305 305 end 306 306 307 copy_table_indexes(from, to )307 copy_table_indexes(from, to, options[:rename] || {}) 308 308 copy_table_contents(from, to, 309 309 @definition.columns.map {|column| column.name}, … … 311 311 end 312 312 313 def copy_table_indexes(from, to ) #:nodoc:313 def copy_table_indexes(from, to, rename = {}) #:nodoc: 314 314 indexes(from).each do |index| 315 315 name = index.name … … 320 320 end 321 321 322 # index name can't be the same 323 opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") } 324 opts[:unique] = true if index.unique 325 add_index(to, index.columns, opts) 322 to_column_names = columns(to).map(&:name) 323 columns = index.columns.map {|c| rename[c] || c }.select do |column| 324 to_column_names.include?(column) 325 end 326 327 unless columns.empty? 328 # index name can't be the same 329 opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") } 330 opts[:unique] = true if index.unique 331 add_index(to, columns, opts) 332 end 326 333 end 327 334 end trunk/activerecord/test/migration_test.rb
r8199 r8453 432 432 end 433 433 434 def test_rename_column_with_an_index 435 ActiveRecord::Base.connection.create_table(:hats) do |table| 436 table.column :hat_name, :string, :limit => 100 437 table.column :hat_size, :integer 438 end 439 Person.connection.add_index :people, :first_name 440 assert_nothing_raised do 441 Person.connection.rename_column "hats", "hat_name", "name" 442 end 443 ensure 444 ActiveRecord::Base.connection.drop_table(:hats) 445 end 446 447 def test_remove_column_with_index 448 ActiveRecord::Base.connection.create_table(:hats) do |table| 449 table.column :hat_name, :string, :limit => 100 450 table.column :hat_size, :integer 451 end 452 ActiveRecord::Base.connection.add_index "hats", "hat_size" 453 454 assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") } 455 ensure 456 ActiveRecord::Base.connection.drop_table(:hats) 457 end 458 459 def test_remove_column_with_multi_column_index 460 ActiveRecord::Base.connection.create_table(:hats) do |table| 461 table.column :hat_name, :string, :limit => 100 462 table.column :hat_size, :integer 463 table.column :hat_style, :string, :limit => 100 464 end 465 ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true 466 467 assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") } 468 ensure 469 ActiveRecord::Base.connection.drop_table(:hats) 470 end 471 434 472 def test_change_type_of_not_null_column 435 473 assert_nothing_raised do