Method: ActiveRecord::ConnectionAdapters::MySQL::SchemaStatements#type_to_sql

Defined in:
activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb

#type_to_sql(type, limit: nil, precision: nil, scale: nil, size: limit_to_size(limit, type), unsigned: nil) ⇒ Object

Maps logical Rails types to MySQL-specific data types.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb', line 112

def type_to_sql(type, limit: nil, precision: nil, scale: nil, size: limit_to_size(limit, type), unsigned: nil, **)
  sql =
    case type.to_s
    when "integer"
      integer_to_sql(limit)
    when "text"
      type_with_size_to_sql("text", size)
    when "blob"
      type_with_size_to_sql("blob", size)
    when "binary"
      if (0..0xfff) === limit
        "varbinary(#{limit})"
      else
        type_with_size_to_sql("blob", size)
      end
    else
      super
    end

  sql = "#{sql} unsigned" if unsigned && type != :primary_key
  sql
end