Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 9f69d42860a56c585271484f49445f1b43dac357 1 parent df048b5
@senny senny authored senny committed
View
6 activerecord/CHANGELOG.md
@@ -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
View
2  activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -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
View
12 activerecord/test/cases/migration_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.