Permalink
Browse files

Backport #8522, Keep index names when using with sqlite3

Conflicts:

	activerecord/CHANGELOG.md
	activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
	activerecord/test/cases/migration/rename_column_test.rb
  • Loading branch information...
1 parent df048b5 commit 9f69d42860a56c585271484f49445f1b43dac357 @senny senny committed with senny Dec 15, 2012
@@ -1,5 +1,11 @@
## 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'.
Fix #8492
Backport of #8500
@@ -530,7 +530,7 @@ def copy_table_indexes(from, to, rename = {}) #:nodoc:
unless columns.empty?
# 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
add_index(to, columns, opts)
end
@@ -1051,6 +1051,18 @@ def test_change_column_with_new_default
Person.connection.remove_column("people", "administrator") rescue nil
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
Person.connection.change_column_default "people", "first_name", "Tester"
Person.reset_column_information

0 comments on commit 9f69d42

Please sign in to comment.