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

Deprecate allowed_index_name_length in DatabaseLimits #39083

Merged
merged 1 commit into from Apr 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord/CHANGELOG.md
@@ -1,4 +1,4 @@
* Deprecate `in_clause_length` in `DatabaseLimits`.
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.

*Ryuta Kamizono*

Expand Down
Expand Up @@ -32,6 +32,7 @@ def table_name_length
def allowed_index_name_length
index_name_length
end
deprecate :allowed_index_name_length

# Returns the maximum length of an index name.
def index_name_length
Expand Down
Expand Up @@ -1441,10 +1441,8 @@ def extract_foreign_key_action(specifier)
end

def validate_index_length!(table_name, new_name, internal = false)
max_index_length = internal ? index_name_length : allowed_index_name_length

if new_name.length > max_index_length
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{allowed_index_name_length} characters"
if new_name.length > index_name_length
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
end
end

Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/adapter_test.rb
Expand Up @@ -411,6 +411,10 @@ def test_joins_per_query_is_deprecated
assert_deprecated { @connection.joins_per_query }
end

def test_allowed_index_name_length_is_deprecated
assert_deprecated { @connection.allowed_index_name_length }
end

unless current_adapter?(:OracleAdapter)
def test_in_clause_length_is_deprecated
assert_deprecated { @connection.in_clause_length }
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/migration/columns_test.rb
Expand Up @@ -254,7 +254,7 @@ def test_change_column_with_custom_index_name

def test_change_column_with_long_index_name
table_name_prefix = "test_models_"
long_index_name = table_name_prefix + ("x" * (connection.allowed_index_name_length - table_name_prefix.length))
long_index_name = table_name_prefix + ("x" * (connection.index_name_length - table_name_prefix.length))
add_column "test_models", "category", :string
add_index :test_models, :category, name: long_index_name

Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/migration/index_test.rb
Expand Up @@ -44,7 +44,7 @@ def test_rename_index_too_long
e = assert_raises(ArgumentError) {
connection.rename_index(table_name, "old_idx", too_long_index_name)
}
assert_match(/too long; the limit is #{connection.allowed_index_name_length} characters/, e.message)
assert_match(/too long; the limit is #{connection.index_name_length} characters/, e.message)

assert connection.index_name_exists?(table_name, "old_idx")
end
Expand All @@ -66,7 +66,7 @@ def test_add_index_does_not_accept_too_long_index_names
e = assert_raises(ArgumentError) {
connection.add_index(table_name, "foo", name: too_long_index_name)
}
assert_match(/too long; the limit is #{connection.allowed_index_name_length} characters/, e.message)
assert_match(/too long; the limit is #{connection.index_name_length} characters/, e.message)

assert_not connection.index_name_exists?(table_name, too_long_index_name)
connection.add_index(table_name, "foo", name: good_index_name)
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_add_partial_index

private
def good_index_name
"x" * connection.allowed_index_name_length
"x" * connection.index_name_length
end
end
end
Expand Down