Skip to content

Commit d548975

Browse files
committed
Deprecate unsigned_float and unsigned_decimal short-hand column methods
As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE, and DECIMAL. Consider using a simple CHECK constraint instead for such columns. https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html Just in case existing `schema.rb` is still valid since the schema dumper dumps un unsigned attribute as `unsigned: true` option. https://github.com/rails/rails/blob/2ae883cc162446ae8ce602c2aa0d08a3ca15c917/activerecord/test/cases/adapters/abstract_mysql_adapter/unsigned_type_test.rb#L61-L67
1 parent 2ae883c commit d548975

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

activerecord/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
* Deprecate `unsigned_float` and `unsigned_decimal` short-hand column methods.
2+
3+
As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE,
4+
and DECIMAL. Consider using a simple CHECK constraint instead for such columns.
5+
6+
https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
7+
8+
*Ryuta Kamizono*
9+
110
* Drop MySQL 5.5 support.
211

312
MySQL 5.5 is the only version that does not support datetime with precision,

activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,12 @@ module ColumnMethods
4242
# :method: unsigned_bigint
4343
# :call-seq: unsigned_bigint(*names, **options)
4444

45-
##
46-
# :method: unsigned_float
47-
# :call-seq: unsigned_float(*names, **options)
48-
49-
##
50-
# :method: unsigned_decimal
51-
# :call-seq: unsigned_decimal(*names, **options)
52-
5345
included do
5446
define_column_methods :blob, :tinyblob, :mediumblob, :longblob,
5547
:tinytext, :mediumtext, :longtext, :unsigned_integer, :unsigned_bigint,
5648
:unsigned_float, :unsigned_decimal
49+
50+
deprecate :unsigned_float, :unsigned_decimal, deprecator: ActiveRecord.deprecator
5751
end
5852
end
5953

activerecord/test/cases/adapters/abstract_mysql_adapter/unsigned_type_test.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,24 @@ class UnsignedType < ActiveRecord::Base
4949
@connection.change_table("unsigned_types") do |t|
5050
t.unsigned_integer :unsigned_integer_t
5151
t.unsigned_bigint :unsigned_bigint_t
52-
t.unsigned_float :unsigned_float_t
53-
t.unsigned_decimal :unsigned_decimal_t, precision: 10, scale: 2
5452
end
5553

5654
@connection.columns("unsigned_types").select { |c| /^unsigned_/.match?(c.name) }.each do |column|
5755
assert_predicate column, :unsigned?
5856
end
5957
end
6058

59+
test "deprecate unsigned_float and unsigned_decimal" do
60+
@connection.change_table("unsigned_types") do |t|
61+
assert_deprecated(ActiveRecord.deprecator) do
62+
t.unsigned_float :unsigned_float_t
63+
end
64+
assert_deprecated(ActiveRecord.deprecator) do
65+
t.unsigned_decimal :unsigned_decimal_t
66+
end
67+
end
68+
end
69+
6170
test "schema dump includes unsigned option" do
6271
schema = dump_table_schema "unsigned_types"
6372
assert_match %r{t\.integer\s+"unsigned_integer",\s+unsigned: true$}, schema

0 commit comments

Comments
 (0)