Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rename_index to change_table. #8266

Merged
merged 1 commit into from
Nov 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,13 @@
## Rails 4.0.0 (unreleased) ## ## 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 * `#pluck` can be used on a relation with `select` clause. Fix #7551


Example: Example:
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def native
# change_table :table do |t| # change_table :table do |t|
# t.column # t.column
# t.index # t.index
# t.rename_index
# t.timestamps # t.timestamps
# t.change # t.change
# t.change_default # t.change_default
Expand Down Expand Up @@ -386,6 +387,13 @@ def index_exists?(column_name, options = {})
@base.index_exists?(@table_name, column_name, options) @base.index_exists?(@table_name, column_name, options)
end 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 # Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
# #
# t.timestamps # t.timestamps
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/migration/change_table_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def test_index_exists_with_options
end end
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 def test_change_changes_column
with_change_table do |t| with_change_table do |t|
@connection.expect :change_column, nil, [:delete_me, :bar, :string, {}] @connection.expect :change_column, nil, [:delete_me, :bar, :string, {}]
Expand Down