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 prefix support to renaming indices #653

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/ecto/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ defmodule Ecto.Migration do
end

def rename(%Index{} = current_index, to: new_name) do
Runner.execute({:rename, current_index, new_name})
Runner.execute({:rename, __prefix__(current_index), new_name})
greg-rychlewski marked this conversation as resolved.
Show resolved Hide resolved
%{current_index | name: new_name}
end

Expand Down
34 changes: 34 additions & 0 deletions test/ecto/migration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,23 @@ defmodule Ecto.MigrationTest do
assert index.prefix == "baz"
end

test "renames an index" do
rename index(:people, [:name]), to: "person_names_idx"
flush()
{_, index, new_name} = last_command()
assert new_name == "person_names_idx"
assert is_nil(index.prefix)
end

@tag prefix: "foo"
test "renames an index with a prefix" do
rename index(:people, [:name]), to: "person_names_idx"
flush()
{_, index, new_name} = last_command()
assert new_name == "person_names_idx"
assert index.prefix == "foo"
end

test "executes a command" do
execute "SELECT 1", "SELECT 2"
flush()
Expand Down Expand Up @@ -1004,6 +1021,23 @@ defmodule Ecto.MigrationTest do
assert {:create, %Index{}} = last_command()
end

test "renames an index" do
rename index(:people, [:name]), to: "person_names_idx"
flush()
{_, index, old_name} = last_command()
assert old_name == :people_name_index
PaulOstazeski marked this conversation as resolved.
Show resolved Hide resolved
assert is_nil(index.prefix)
end

@tag prefix: "foo"
test "renames an index with a prefix" do
rename index(:people, [:name]), to: "person_names_idx"
flush()
{_, index, old_name} = last_command()
assert old_name == :people_name_index
assert index.prefix == "foo"
end

test "drops a constraint" do
assert_raise Ecto.MigrationError, ~r/cannot reverse migration command/, fn ->
drop_if_exists constraint(:posts, :price)
Expand Down
Loading