Skip to content

Commit ab2d859

Browse files
committed
Deprecate allowed_index_name_length in DatabaseLimits
`allowed_index_name_length` was used for internal temporary operations in SQLite3, since index name in SQLite3 must be globally unique and SQLite3 doesn't have ALTER TABLE feature (so it is emulated by creating temporary table with prefix). `allowed_index_name_length` was to reserve the margin for the prefix, but actually SQLite3 doesn't have a limitation for identifier name length, so the margin has removed at 36901e6. Now `allowed_index_name_length` is no longer relied on by any adapter, so I'd like to remove the internal specific method which is no longer used.
1 parent 92d0385 commit ab2d859

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

activerecord/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* Deprecate `in_clause_length` in `DatabaseLimits`.
1+
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
22

33
*Ryuta Kamizono*
44

activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def table_name_length
3232
def allowed_index_name_length
3333
index_name_length
3434
end
35+
deprecate :allowed_index_name_length
3536

3637
# Returns the maximum length of an index name.
3738
def index_name_length

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,8 @@ def extract_foreign_key_action(specifier)
14411441
end
14421442

14431443
def validate_index_length!(table_name, new_name, internal = false)
1444-
max_index_length = internal ? index_name_length : allowed_index_name_length
1445-
1446-
if new_name.length > max_index_length
1447-
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{allowed_index_name_length} characters"
1444+
if new_name.length > index_name_length
1445+
raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
14481446
end
14491447
end
14501448

activerecord/test/cases/adapter_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ def test_joins_per_query_is_deprecated
411411
assert_deprecated { @connection.joins_per_query }
412412
end
413413

414+
def test_allowed_index_name_length_is_deprecated
415+
assert_deprecated { @connection.allowed_index_name_length }
416+
end
417+
414418
unless current_adapter?(:OracleAdapter)
415419
def test_in_clause_length_is_deprecated
416420
assert_deprecated { @connection.in_clause_length }

activerecord/test/cases/migration/columns_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_change_column_with_custom_index_name
254254

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

activerecord/test/cases/migration/index_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_rename_index_too_long
4444
e = assert_raises(ArgumentError) {
4545
connection.rename_index(table_name, "old_idx", too_long_index_name)
4646
}
47-
assert_match(/too long; the limit is #{connection.allowed_index_name_length} characters/, e.message)
47+
assert_match(/too long; the limit is #{connection.index_name_length} characters/, e.message)
4848

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

7171
assert_not connection.index_name_exists?(table_name, too_long_index_name)
7272
connection.add_index(table_name, "foo", name: good_index_name)
@@ -229,7 +229,7 @@ def test_add_partial_index
229229

230230
private
231231
def good_index_name
232-
"x" * connection.allowed_index_name_length
232+
"x" * connection.index_name_length
233233
end
234234
end
235235
end

0 commit comments

Comments
 (0)