diff options
author | Hubert DÄ…browski <h@dabrow.org> | 2014-02-12 22:23:16 +0100 |
---|---|---|
committer | Hubert DÄ…browski <h@dabrow.org> | 2014-02-13 17:18:16 +0100 |
commit | e1d4673102f7c4e58964a6de864402ae9a615688 (patch) | |
tree | 636ea2effaf872112186d00b7a91b91db05102db /activerecord/test/cases/invertible_migration_test.rb | |
parent | 4dc42045e20114783a17a0c286b065a3969e6025 (diff) | |
download | rails-e1d4673102f7c4e58964a6de864402ae9a615688.tar.gz rails-e1d4673102f7c4e58964a6de864402ae9a615688.tar.bz2 rails-e1d4673102f7c4e58964a6de864402ae9a615688.zip |
Drop the correct index after reverting a migration
Previously when reverting a migration which added a named index it
would instead drop a corresponding index with matching columns but
without a name.
Diffstat (limited to 'activerecord/test/cases/invertible_migration_test.rb')
-rw-r--r-- | activerecord/test/cases/invertible_migration_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index 428145d00b..debacf815c 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -106,6 +106,22 @@ module ActiveRecord end end + class RevertNamedIndexMigration1 < SilentMigration + def change + create_table("horses") do |t| + t.column :content, :string + t.column :remind_at, :datetime + end + add_index :horses, :content + end + end + + class RevertNamedIndexMigration2 < SilentMigration + def change + add_index :horses, :content, name: "horses_index_named" + end + end + def teardown %w[horses new_horses].each do |table| if ActiveRecord::Base.connection.table_exists?(table) @@ -255,5 +271,17 @@ module ActiveRecord ActiveRecord::Base.table_name_prefix = ActiveRecord::Base.table_name_suffix = '' end + def test_migrate_revert_add_index_with_name + RevertNamedIndexMigration1.new.migrate(:up) + RevertNamedIndexMigration2.new.migrate(:up) + RevertNamedIndexMigration2.new.migrate(:down) + + connection = ActiveRecord::Base.connection + assert connection.index_exists?(:horses, :content), + "index on content should exist" + assert !connection.index_exists?(:horses, :content, name: "horses_index_named"), + "horses_index_named index should not exist" + end + end end |