In a Rails Migration, specifying a column as binary generates a blob column. Blob columns, unfortunately, are allocated differently than any other MySQL column type; specifically, they aren’t supported in memory engine-backed tables.
Varbinary columns, on the other hand, are supported. In order to provide varbinary columns in a Migration, I wrote up this simple core extension.
# Specify :varbinary => true in column creation # No support yet for altering tables to varbinary class ActiveRecord::ConnectionAdapters::MysqlAdapter < AbstractAdapter def type_to_sql_with_varbinary(type, limit = nil, precision = nil, scale = nil) return type_to_sql_without_varbinary(type, limit, precision, scale) unless :varbinary == type.to_sym "varbinary(#{limit})" end alias_method_chain :type_to_sql, :varbinary end class ActiveRecord::ConnectionAdapters::TableDefinition def column_with_varbinary name, type, options = {} return column_without_varbinary name, "varbinary", options if options.delete(:varbinary) column_without_varbinary name, type, options end alias_method_chain :column, :varbinary end
Leave a Comment