Skip to content

Commit

Permalink
Merge pull request rails#52828 from kamipo/deprecate_unsigned_float_d…
Browse files Browse the repository at this point in the history
…ecimal

Deprecate `unsigned_float` and `unsigned_decimal` short-hand column methods
  • Loading branch information
kamipo authored Sep 7, 2024
2 parents 8b0c807 + d548975 commit 1f64e4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
9 changes: 9 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
* 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

*Ryuta Kamizono*

* Drop MySQL 5.5 support.

MySQL 5.5 is the only version that does not support datetime with precision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@ module ColumnMethods
# :method: unsigned_bigint
# :call-seq: unsigned_bigint(*names, **options)

##
# :method: unsigned_float
# :call-seq: unsigned_float(*names, **options)

##
# :method: unsigned_decimal
# :call-seq: unsigned_decimal(*names, **options)

included do
define_column_methods :blob, :tinyblob, :mediumblob, :longblob,
:tinytext, :mediumtext, :longtext, :unsigned_integer, :unsigned_bigint,
:unsigned_float, :unsigned_decimal

deprecate :unsigned_float, :unsigned_decimal, deprecator: ActiveRecord.deprecator
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,24 @@ class UnsignedType < ActiveRecord::Base
@connection.change_table("unsigned_types") do |t|
t.unsigned_integer :unsigned_integer_t
t.unsigned_bigint :unsigned_bigint_t
t.unsigned_float :unsigned_float_t
t.unsigned_decimal :unsigned_decimal_t, precision: 10, scale: 2
end

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

test "deprecate unsigned_float and unsigned_decimal" do
@connection.change_table("unsigned_types") do |t|
assert_deprecated(ActiveRecord.deprecator) do
t.unsigned_float :unsigned_float_t
end
assert_deprecated(ActiveRecord.deprecator) do
t.unsigned_decimal :unsigned_decimal_t
end
end
end

test "schema dump includes unsigned option" do
schema = dump_table_schema "unsigned_types"
assert_match %r{t\.integer\s+"unsigned_integer",\s+unsigned: true$}, schema
Expand Down

0 comments on commit 1f64e4d

Please sign in to comment.