Skip to content

Commit

Permalink
Merge pull request #8558 from senny/backport_3489
Browse files Browse the repository at this point in the history
Backport #8522, Keep index names when using  with sqlite3
  • Loading branch information
carlosantoniodasilva committed Dec 19, 2012
2 parents df048b5 + 9f69d42 commit bf16699
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,11 @@
## Rails 3.2.10 (unreleased) ## Rails 3.2.10 (unreleased)


* Keep index names when using `alter_table` with sqlite3.
Fix #3489
Backport #8522

*Yves Senn*

* Recognize migrations placed in directories containing numbers and 'rb'. * Recognize migrations placed in directories containing numbers and 'rb'.
Fix #8492 Fix #8492
Backport of #8500 Backport of #8500
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def copy_table_indexes(from, to, rename = {}) #:nodoc:


unless columns.empty? unless columns.empty?
# index name can't be the same # index name can't be the same
opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") } opts = { :name => name.gsub(/(^|_)(#{from})_/, "\\1#{to}_") }
opts[:unique] = true if index.unique opts[:unique] = true if index.unique
add_index(to, columns, opts) add_index(to, columns, opts)
end end
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/migration_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1051,6 +1051,18 @@ def test_change_column_with_new_default
Person.connection.remove_column("people", "administrator") rescue nil Person.connection.remove_column("people", "administrator") rescue nil
end end


def test_change_column_with_custom_index_name
Person.connection.add_column "people", "category", :string, :default => 'human'
Person.connection.add_index :people, :category, :name => 'people_categories_idx'

assert_equal ['people_categories_idx'], Person.connection.indexes('people').map(&:name)
Person.connection.change_column "people", "category", :string, :null => false, :default => 'article'

assert_equal ['people_categories_idx'], Person.connection.indexes('people').map(&:name)
ensure
Person.connection.remove_column("people", "category") rescue nil
end

def test_change_column_default def test_change_column_default
Person.connection.change_column_default "people", "first_name", "Tester" Person.connection.change_column_default "people", "first_name", "Tester"
Person.reset_column_information Person.reset_column_information
Expand Down

0 comments on commit bf16699

Please sign in to comment.