class ActiveRecord::ConnectionAdapters::MysqlColumn
:nodoc:
def extract_default(default)
def extract_default(default) if sql_type =~ /blob/i || type == :text if default.blank? return null ? nil : '' else raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}" end elsif missing_default_forged_as_empty_string?(default) nil else super end end
def extract_limit(sql_type)
def extract_limit(sql_type) case sql_type when /blob|text/i case sql_type when /tiny/i 255 when /medium/i 16777215 when /long/i 2147483647 # mysql only allows 2^31-1, not 2^32-1, somewhat inconsistently with the tiny/medium/normal cases else super # we could return 65535 here, but we leave it undecorated by default end when /^bigint/i; 8 when /^int/i; 4 when /^mediumint/i; 3 when /^smallint/i; 2 when /^tinyint/i; 1 else super end end
def has_default?
def has_default? return false if sql_type =~ /blob/i || type == :text #mysql forbids defaults on blob and text columns super end
def missing_default_forged_as_empty_string?(default)
Test whether the column has default '', is not null, and is not
and the rest).
default (string) but we can for others (integer, datetime, boolean,
We can't detect this for columns which may have a legitimate ''
MySQL misreports NOT NULL column default when none is given.
def missing_default_forged_as_empty_string?(default) type != :string && !null && default == '' end
def simplified_type(field_type)
def simplified_type(field_type) return :boolean if MysqlAdapter.emulate_booleans && field_type.downcase.index("tinyint(1)") return :string if field_type =~ /enum/i super end