aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-19 03:33:51 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-19 03:33:51 -0800
commitbf166996f2985c7952b1d27ba4c1789f6b6e4161 (patch)
tree6ad4736a3358305efff45b821e5afa965bb9d546 /activerecord
parentdf048b574b5ab5a449a3b1dfc50dbf3baa18869e (diff)
parent9f69d42860a56c585271484f49445f1b43dac357 (diff)
downloadrails-bf166996f2985c7952b1d27ba4c1789f6b6e4161.tar.gz
rails-bf166996f2985c7952b1d27ba4c1789f6b6e4161.tar.bz2
rails-bf166996f2985c7952b1d27ba4c1789f6b6e4161.zip
Merge pull request #8558 from senny/backport_3489
Backport #8522, Keep index names when using with sqlite3
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb2
-rw-r--r--activerecord/test/cases/migration_test.rb12
3 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 0b22939884..c39d7fe00c 100644
--- a/activerecord/CHANGELOG.md
+++ b/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
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index e80b465bab..ca84c95bdc 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -530,7 +530,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index ff633f7f0f..7bb71b7b6e 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -1051,6 +1051,18 @@ if ActiveRecord::Base.connection.supports_migrations?
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