aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2015-02-14 15:59:33 +0900
committerRyuta Kamizono <kamipo@gmail.com>2015-09-18 20:22:32 +0900
commitdfeb3ee78a44b630ef414a7ce6e93265b2cc4f28 (patch)
treef48fc57752bc45c297ef9c195f6b3d09afb5f9ed /activerecord/lib/active_record
parentf3772f729c72d098156b35eb105d3ffdd928c5eb (diff)
downloadrails-dfeb3ee78a44b630ef414a7ce6e93265b2cc4f28.tar.gz
rails-dfeb3ee78a44b630ef414a7ce6e93265b2cc4f28.tar.bz2
rails-dfeb3ee78a44b630ef414a7ce6e93265b2cc4f28.zip
Add `unsigned` types for numeric data types in MySQL
In the case of using `unsigned` as the type: create_table :foos do |t| t.unsigned_integer :unsigned_integer t.unsigned_bigint :unsigned_bigint t.unsigned_float :unsigned_float t.unsigned_decimal :unsigned_decimal, precision: 10, scale: 2 end
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb21
1 files changed, 21 insertions, 0 deletions
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 55de098f70..245d476abb 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -14,6 +14,22 @@ module ActiveRecord
def json(*args, **options)
args.each { |name| column(name, :json, options) }
end
+
+ def unsigned_integer(*args, **options)
+ args.each { |name| column(name, :unsigned_integer, options) }
+ end
+
+ def unsigned_bigint(*args, **options)
+ args.each { |name| column(name, :unsigned_bigint, options) }
+ end
+
+ def unsigned_float(*args, **options)
+ args.each { |name| column(name, :unsigned_float, options) }
+ end
+
+ def unsigned_decimal(*args, **options)
+ args.each { |name| column(name, :unsigned_decimal, options) }
+ end
end
class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
@@ -29,6 +45,9 @@ module ActiveRecord
when :primary_key
column.type = :integer
column.auto_increment = true
+ when /\Aunsigned_(?<type>.+)\z/
+ column.type = $~[:type].to_sym
+ column.unsigned = true
end
column.unsigned ||= options[:unsigned]
column.charset = options[:charset]
@@ -1108,6 +1127,8 @@ module ActiveRecord
ActiveRecord::Type.register(:json, MysqlJson, adapter: :mysql2)
ActiveRecord::Type.register(:string, MysqlString, adapter: :mysql)
ActiveRecord::Type.register(:string, MysqlString, adapter: :mysql2)
+ ActiveRecord::Type.register(:unsigned_integer, Type::UnsignedInteger, adapter: :mysql)
+ ActiveRecord::Type.register(:unsigned_integer, Type::UnsignedInteger, adapter: :mysql2)
end
end
end