Commit d5e91856 authored by Olivier Gonzalez's avatar Olivier Gonzalez

Make MySQL patch for binary indexes compatible with composite indexes

parent 91003c6e
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
# the old Rails 4 schema layout is still used # the old Rails 4 schema layout is still used
module MysqlSetLengthForBinaryIndex module MysqlSetLengthForBinaryIndex
def add_index(table_name, column_names, options = {}) def add_index(table_name, column_names, options = {})
options[:length] ||= {}
Array(column_names).each do |column_name| Array(column_names).each do |column_name|
column = ActiveRecord::Base.connection.columns(table_name).find { |c| c.name == column_name } column = ActiveRecord::Base.connection.columns(table_name).find { |c| c.name == column_name }
if column&.type == :binary if column&.type == :binary
options[:length] = 20 options[:length][column_name] = 20
end end
end end
...@@ -27,11 +28,12 @@ if Gitlab.rails5? ...@@ -27,11 +28,12 @@ if Gitlab.rails5?
module MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema module MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema
# This method is used in Rails 5 schema loading as t.index # This method is used in Rails 5 schema loading as t.index
def index(column_names, options = {}) def index(column_names, options = {})
options[:length] ||= {}
Array(column_names).each do |column_name| Array(column_names).each do |column_name|
column = columns.find { |c| c.name == column_name } column = columns.find { |c| c.name == column_name }
if column&.type == :binary if column&.type == :binary
options[:length] = 20 options[:length][column_name] = 20
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment