Skip to content

Commit afd265d

Browse files
committed
Remove deprecated calls to String#mb_chars in ActiveRecord
Related to rails#54081 cc @byroot When adding an index like the following : ```ruby add_reference :posts, :user, foreign_key: { on_delete: :nullify }, index: true, null: true ``` This triggers a deprecation warning. The fix is to use `String#truncate_bytes` from ActiveSupport to properly limit the index name size.
1 parent 1a2771a commit afd265d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ def generate_index_name(table_name, column)
16051605
name = "idx_on_#{Array(column) * '_'}"
16061606

16071607
short_limit = max_index_name_size - hashed_identifier.bytesize
1608-
short_name = name.mb_chars.limit(short_limit).to_s
1608+
short_name = name.truncate_bytes(short_limit, omission: nil)
16091609

16101610
"#{short_name}#{hashed_identifier}"
16111611
end

0 commit comments

Comments
 (0)