Merge pull request #22941 from lsylvester/pg-remove-index-legacy
Fix remove_index for postgresql when running legacy migrations
This commit is contained in:
commit
998b85ffe8
@ -41,8 +41,9 @@ def index_exists?(table_name, column_name, options = {})
|
||||
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
|
||||
|
@ -21,6 +21,7 @@ def setup
|
||||
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 @@ def migrate(x)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user