Skip to content
Snippets Groups Projects
Commit 08005d47 authored by Alexis Reigel's avatar Alexis Reigel :coffee:
Browse files

mysql hack: set length for binary indexes

parent abcd9dbc
No related branches found
No related tags found
Loading
This commit is part of merge request !9546. Comments created here will be created in the context of that merge request.
# This patches ActiveRecord so indexes for binary columns created using the
# MySQL adapter apply a length of 20. Otherwise MySQL can't create an index on
# binary columns.
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
module ActiveRecord
module ConnectionAdapters
class Mysql2Adapter < AbstractMysqlAdapter
alias_method :__gitlab_add_index2, :add_index
def add_index(table_name, column_name, options = {})
column = ActiveRecord::Base.connection.columns(table_name).first { |c| c.name == column_name }
puts "--> mysql hack: #{table_name}, #{column_name}, #{column.type}"
if column.type == :binary
options[:length] = 20
end
__gitlab_add_index2(table_name, column_name, options)
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment