aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-18 17:14:07 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-18 17:14:07 -0800
commitf460835dd5ebcede6f02e0459a7e6f8271b9047c (patch)
treec56300df07949f6d9180876a57c9e0b228c5fce2
parente21579f1d11983ab3296e530afafd836d6e29b1f (diff)
parent1a782b2b634cadbea2ae194848e97ca0ecdbce30 (diff)
downloadrails-f460835dd5ebcede6f02e0459a7e6f8271b9047c.tar.gz
rails-f460835dd5ebcede6f02e0459a7e6f8271b9047c.tar.bz2
rails-f460835dd5ebcede6f02e0459a7e6f8271b9047c.zip
Merge pull request #8266 from CvX/index_rename
Add rename_index to change_table.
-rw-r--r--activerecord/CHANGELOG.md8
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb8
-rw-r--r--activerecord/test/cases/migration/change_table_test.rb7
3 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 4fa2dcb847..82e90e665b 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,13 @@
## Rails 4.0.0 (unreleased) ##
+* `rename_index` can be used inside a `change_table` block.
+
+ change_table :accounts do |t|
+ t.rename_index :user_id, :account_id
+ end
+
+ *Jarek Radosz*
+
* `#pluck` can be used on a relation with `select` clause. Fix #7551
Example:
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 38960ab873..7ec6abbc45 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -324,6 +324,7 @@ module ActiveRecord
# change_table :table do |t|
# t.column
# t.index
+ # t.rename_index
# t.timestamps
# t.change
# t.change_default
@@ -386,6 +387,13 @@ module ActiveRecord
@base.index_exists?(@table_name, column_name, options)
end
+ # Renames the given index on the table.
+ #
+ # t.rename_index(:user_id, :account_id)
+ def rename_index(index_name, new_index_name)
+ @base.rename_index(@table_name, index_name, new_index_name)
+ end
+
# Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
#
# t.timestamps
diff --git a/activerecord/test/cases/migration/change_table_test.rb b/activerecord/test/cases/migration/change_table_test.rb
index 4614be9650..8fb03cdee0 100644
--- a/activerecord/test/cases/migration/change_table_test.rb
+++ b/activerecord/test/cases/migration/change_table_test.rb
@@ -164,6 +164,13 @@ module ActiveRecord
end
end
+ def test_rename_index_renames_index
+ with_change_table do |t|
+ @connection.expect :rename_index, nil, [:delete_me, :bar, :baz]
+ t.rename_index :bar, :baz
+ end
+ end
+
def test_change_changes_column
with_change_table do |t|
@connection.expect :change_column, nil, [:delete_me, :bar, :string, {}]