aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-11-29 11:10:39 -0500
committerGitHub <noreply@github.com>2016-11-29 11:10:39 -0500
commit4806317b65314c28a2608fc4e55fb0a160db2b7d (patch)
tree3491b739a590870ea593ce2a1264834f77f7f1a8 /activerecord
parent47b20c7ff74c72ade4c3c9c4a134166ebdbc400f (diff)
parent32ea84df6f4236125ea9e1f91a0685ccea2bfe4a (diff)
downloadrails-4806317b65314c28a2608fc4e55fb0a160db2b7d.tar.gz
rails-4806317b65314c28a2608fc4e55fb0a160db2b7d.tar.bz2
rails-4806317b65314c28a2608fc4e55fb0a160db2b7d.zip
Merge pull request #27126 from kamipo/fix_unsigned_with_zerofill
Fix that unsigned with zerofill is treated as signed
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/column.rb2
-rw-r--r--activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb1
4 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 64a0e22af2..08dd40080f 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Fix that unsigned with zerofill is treated as signed.
+
+ Fixes #27125.
+
+ *Ryuta Kamizono*
+
* Fix the uniqueness validation scope with a polymorphic association.
*Sergey Alekseev*
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index cbbba5b1a5..98152853c2 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -693,7 +693,7 @@ module ActiveRecord
def register_integer_type(mapping, key, options) # :nodoc:
mapping.register_type(key) do |sql_type|
- if /\bunsigned\z/.match?(sql_type)
+ if /\bunsigned\b/.match?(sql_type)
Type::UnsignedInteger.new(options)
else
Type::Integer.new(options)
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/column.rb b/activerecord/lib/active_record/connection_adapters/mysql/column.rb
index f82c556a6f..22b9df5309 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/column.rb
@@ -5,7 +5,7 @@ module ActiveRecord
delegate :extra, to: :sql_type_metadata, allow_nil: true
def unsigned?
- /\bunsigned\z/.match?(sql_type)
+ !/\A(?:enum|set)\b/.match?(sql_type) && /\bunsigned\b/.match?(sql_type)
end
def case_sensitive?
diff --git a/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb b/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb
index 452f8d5ae8..59475ad177 100644
--- a/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb
@@ -48,6 +48,7 @@ class Mysql2UnsignedTypeTest < ActiveRecord::Mysql2TestCase
t.unsigned_bigint :unsigned_bigint_t
t.unsigned_float :unsigned_float_t
t.unsigned_decimal :unsigned_decimal_t, precision: 10, scale: 2
+ t.column :unsigned_zerofill, "int unsigned zerofill"
end
@connection.columns("unsigned_types").select { |c| /^unsigned_/.match?(c.name) }.each do |column|