mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #40421 from ayamomiji/master
Fix rename_index removing old index with symbols
This commit is contained in:
commit
872e757145
2 changed files with 11 additions and 0 deletions
|
@ -890,6 +890,8 @@ module ActiveRecord
|
||||||
# rename_index :people, 'index_people_on_last_name', 'index_users_on_last_name'
|
# rename_index :people, 'index_people_on_last_name', 'index_users_on_last_name'
|
||||||
#
|
#
|
||||||
def rename_index(table_name, old_name, new_name)
|
def rename_index(table_name, old_name, new_name)
|
||||||
|
old_name = old_name.to_s
|
||||||
|
new_name = new_name.to_s
|
||||||
validate_index_length!(table_name, new_name)
|
validate_index_length!(table_name, new_name)
|
||||||
|
|
||||||
# this is a naive implementation; some DBs may support this more efficiently (PostgreSQL, for instance)
|
# this is a naive implementation; some DBs may support this more efficiently (PostgreSQL, for instance)
|
||||||
|
|
|
@ -37,6 +37,15 @@ module ActiveRecord
|
||||||
assert connection.index_name_exists?(table_name, "new_idx")
|
assert connection.index_name_exists?(table_name, "new_idx")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rename_index_with_symbol
|
||||||
|
# keep the names short to make Oracle and similar behave
|
||||||
|
connection.add_index(table_name, [:foo], name: :old_idx)
|
||||||
|
connection.rename_index(table_name, :old_idx, :new_idx)
|
||||||
|
|
||||||
|
assert_not connection.index_name_exists?(table_name, "old_idx")
|
||||||
|
assert connection.index_name_exists?(table_name, "new_idx")
|
||||||
|
end
|
||||||
|
|
||||||
def test_rename_index_too_long
|
def test_rename_index_too_long
|
||||||
too_long_index_name = good_index_name + "x"
|
too_long_index_name = good_index_name + "x"
|
||||||
# keep the names short to make Oracle and similar behave
|
# keep the names short to make Oracle and similar behave
|
||||||
|
|
Loading…
Reference in a new issue