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

Suggesting a better message #143

Merged
merged 2 commits into from
Jul 20, 2023
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
4 changes: 3 additions & 1 deletion lib/active_record_doctor/detectors/extraneous_indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def message(extraneous_index:, replacement_indexes:)
if replacement_indexes.nil?
"remove #{extraneous_index} - coincides with the primary key on the table"
else
"remove #{extraneous_index} - can be replaced by #{replacement_indexes.join(' or ')}"
# rubocop:disable Layout/LineLength
"remove #{extraneous_index} - queries should be able to use the following #{'index'.pluralize(replacement_indexes.count)} instead: #{replacement_indexes.join(' or ')}"
# rubocop:enable Layout/LineLength
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/active_record_doctor/detectors/extraneous_indexes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_non_unique_version_of_index_is_duplicate
ActiveRecord::Base.connection.add_index :users, :email, name: "index_users_on_email"

assert_problems(<<OUTPUT)
remove index_users_on_email - can be replaced by unique_index_on_users_email
remove index_users_on_email - queries should be able to use the following index instead: unique_index_on_users_email
OUTPUT
end

Expand All @@ -59,7 +59,7 @@ def test_single_column_covered_by_unique_and_non_unique_multi_column_is_duplicat
end

assert_problems(<<OUTPUT)
remove index_users_on_last_name - can be replaced by index_users_on_last_name_and_first_name_and_email or unique_index_on_users_last_name_and_first_name
remove index_users_on_last_name - queries should be able to use the following indices instead: index_users_on_last_name_and_first_name_and_email or unique_index_on_users_last_name_and_first_name
OUTPUT
end

Expand All @@ -78,7 +78,7 @@ def test_multi_column_covered_by_unique_and_non_unique_multi_column_is_duplicate
ActiveRecord::Base.connection.add_index :users, [:last_name, :first_name]

assert_problems(<<OUTPUT)
remove index_users_on_last_name_and_first_name - can be replaced by index_users_on_last_name_and_first_name_and_email or unique_index_on_users_last_name_and_first_name
remove index_users_on_last_name_and_first_name - queries should be able to use the following indices instead: index_users_on_last_name_and_first_name_and_email or unique_index_on_users_last_name_and_first_name
OUTPUT
end

Expand All @@ -91,7 +91,7 @@ def test_unique_index_with_fewer_columns
end

assert_problems(<<OUTPUT)
remove index_users_on_last_name_and_first_name - can be replaced by index_users_on_first_name
remove index_users_on_last_name_and_first_name - queries should be able to use the following index instead: index_users_on_first_name
OUTPUT
end

Expand Down Expand Up @@ -159,7 +159,7 @@ def test_single_column_covered_by_multi_column_on_materialized_view_is_duplicate
connection.add_index(:user_initials, :last_name)

assert_problems(<<OUTPUT)
remove index_user_initials_on_last_name - can be replaced by index_user_initials_on_last_name_and_first_name
remove index_user_initials_on_last_name - queries should be able to use the following index instead: index_user_initials_on_last_name_and_first_name
OUTPUT
ensure
connection.execute("DROP MATERIALIZED VIEW user_initials")
Expand Down