提交 ba6b3c16 编写于 作者: R Rafael Mendonça França

Merge pull request #8868 from tehgeekmeister/master

Use the index name explicitly provided in a migration when reverting.

Fixes #8868

Conflicts:
	activerecord/CHANGELOG.md
## Rails 4.0.0 (unreleased) ##
* When `:name` option is provided to `remove_index`, use it if there is no
index by the conventional name.
For example, previously if an index was removed like so
`remove_index :values, column: :value, name: 'a_different_name'`
the generated SQL would not contain the specified index name,
and hence the migration would fail.
Fixes #8858.
*Ezekiel Smithburg*
* Created block to by-pass the prepared statement bindings.
This will allow to compose fragments of large SQL statements to
avoid multiple round-trips between Ruby and the DB.
......
......@@ -687,6 +687,12 @@ def index_name_for_remove(table_name, options = {})
index_name = index_name(table_name, options)
unless index_name_exists?(table_name, index_name, true)
if options.has_key? :name
options_without_column = options.dup
options_without_column.delete :column
index_name_without_column = index_name(table_name, options_without_column)
return index_name_without_column if index_name_exists?(table_name, index_name_without_column, false)
end
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
end
......
......@@ -462,6 +462,22 @@ def test_drop_index_from_table_named_values
end
end
class ExplicitlyNamedIndexMigrationTest < ActiveRecord::TestCase
def test_drop_index_by_name
connection = Person.connection
connection.create_table :values, force: true do |t|
t.integer :value
end
assert_nothing_raised ArgumentError do
connection.add_index :values, :value, name: 'a_different_name'
connection.remove_index :values, column: :value, name: 'a_different_name'
end
connection.drop_table :values rescue nil
end
end
if ActiveRecord::Base.connection.supports_bulk_alter?
class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
def setup
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册