未验证 提交 e6ad2e4c 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #39083 from kamipo/deprecate_allowed_index_name_length

Deprecate `allowed_index_name_length` in `DatabaseLimits`
* Deprecate `in_clause_length` in `DatabaseLimits`.
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
*Ryuta Kamizono*
......
......@@ -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
......
......@@ -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
......
......@@ -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 }
......
......@@ -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
......
......@@ -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
......@@ -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)
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册