diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-03-01 14:03:31 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-03-04 17:51:47 +0900 |
commit | 5366cc6b55a2d00ce99440d11821dde8b5868f94 (patch) | |
tree | b6a4a4b0fcf081ededea8b06ef20ec93f05f3781 /activerecord | |
parent | 1b356c2e7ad4eaf5ed16584501c586d1893b8eed (diff) | |
download | rails-5366cc6b55a2d00ce99440d11821dde8b5868f94.tar.gz rails-5366cc6b55a2d00ce99440d11821dde8b5868f94.tar.bz2 rails-5366cc6b55a2d00ce99440d11821dde8b5868f94.zip |
Add `Column#bigint?` method
Diffstat (limited to 'activerecord')
3 files changed, 7 insertions, 3 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 c084431588..9625fcf9b8 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -86,8 +86,8 @@ module ActiveRecord def column_spec_for_primary_key(column) spec = {} if column.auto_increment? - return unless column.limit == 8 - spec[:id] = ':bigint' + spec[:id] = ':bigint' if column.bigint? + return if spec.empty? else spec[:id] = column.type.inspect spec.merge!(prepare_column_options(column).delete_if { |key, _| [:name, :type, :null].include?(key) }) diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index fa5ed07b8a..c05a8aa1ad 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -34,6 +34,10 @@ module ActiveRecord !default.nil? end + def bigint? + /bigint/ === sql_type + end + # Returns the human name of the column name. # # ===== Examples diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 6d25b53b21..094a9382ae 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -128,7 +128,7 @@ module ActiveRecord def column_spec_for_primary_key(column) spec = {} if column.serial? - return unless column.sql_type == 'bigint' + return unless column.bigint? spec[:id] = ':bigserial' elsif column.type == :uuid spec[:id] = ':uuid' |