Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5489: change_pg_limit_translation.diff

File change_pg_limit_translation.diff, 0.7 kB (added by pedrobelo@gmail.com <pedrobelo@gmail.com>, 4 years ago)

changes PostgreSQL adapter rules to translate limit according to the oficial docs

  • lib/active_record/connection_adapters/postgresql_adapter.rb

    old new  
    355355 
    356356      def type_to_sql(type, limit = nil) #:nodoc: 
    357357        return super unless type.to_s == 'integer' 
    358  
    359         if limit.nil? || limit == 4 
    360           'integer' 
    361         elsif limit < 4 
    362           'smallint' 
    363         else 
    364           'bigint' 
     358        case limit 
     359          when 1..2:      'smallint' 
     360          when 3..4, nil: 'integer' 
     361          when 5..8:      'bigint' 
    365362        end 
    366363      end 
    367364