diff options
author | Lachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au> | 2016-01-05 15:40:34 +1100 |
---|---|---|
committer | Lachlan Sylvester <lachlan.sylvester@hypothetical.com.au> | 2016-01-06 19:20:11 +1100 |
commit | 76dc41abdb33f69c078818dd8142bdf47834baa5 (patch) | |
tree | d5918f5db139421792cd1fdb51ba94b025dc2264 | |
parent | 0ff3e9466a4f476ee2e56d9e2b40acce01924683 (diff) | |
download | rails-76dc41abdb33f69c078818dd8142bdf47834baa5.tar.gz rails-76dc41abdb33f69c078818dd8142bdf47834baa5.tar.bz2 rails-76dc41abdb33f69c078818dd8142bdf47834baa5.zip |
fix remove_index for postgresql when running legacy migrations
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/migration/compatibility_test.rb | 16 |
2 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index 831bfa2df3..1b94573870 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -41,8 +41,9 @@ module ActiveRecord end def remove_index(table_name, options = {}) - index_name = index_name_for_remove(table_name, options) - execute "DROP INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}" + options = { column: options } unless options.is_a?(Hash) + options[:name] = index_name_for_remove(table_name, options) + super(table_name, options) end private diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb index 267d2fcccc..b1e1d72944 100644 --- a/activerecord/test/cases/migration/compatibility_test.rb +++ b/activerecord/test/cases/migration/compatibility_test.rb @@ -21,6 +21,7 @@ module ActiveRecord teardown do connection.drop_table :testings rescue nil ActiveRecord::Migration.verbose = @verbose_was + ActiveRecord::SchemaMigration.delete_all end def test_migration_doesnt_remove_named_index @@ -37,6 +38,21 @@ module ActiveRecord assert_raise(StandardError) { ActiveRecord::Migrator.new(:up, [migration]).migrate } assert connection.index_exists?(:testings, :foo, name: "custom_index_name") end + + def test_migration_does_remove_unnamed_index + connection.add_index :testings, :bar + + migration = Class.new(ActiveRecord::Migration[4.2]) { + def version; 101 end + def migrate(x) + remove_index :testings, :bar + end + }.new + + assert connection.index_exists?(:testings, :bar) + ActiveRecord::Migrator.new(:up, [migration]).migrate + assert_not connection.index_exists?(:testings, :bar) + end end end end |