mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
reducing range comparisons when converting types to sql
This commit is contained in:
@@ -848,11 +848,12 @@ module ActiveRecord
|
||||
# Maps logical Rails types to PostgreSQL-specific data types.
|
||||
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
|
||||
return super unless type.to_s == 'integer'
|
||||
return 'integer' unless limit
|
||||
|
||||
case limit
|
||||
when 1..2; 'smallint'
|
||||
when 3..4, nil; 'integer'
|
||||
when 5..8; 'bigint'
|
||||
when 1, 2; 'smallint'
|
||||
when 3, 4; 'integer'
|
||||
when 5..8; 'bigint'
|
||||
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user