From d5e9185618cc30227b2bd68f4322a3d7860152ee Mon Sep 17 00:00:00 2001 From: Olivier Gonzalez Date: Tue, 4 Sep 2018 18:52:03 -0400 Subject: Make MySQL patch for binary indexes compatible with composite indexes --- config/initializers/mysql_set_length_for_binary_indexes.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/initializers/mysql_set_length_for_binary_indexes.rb b/config/initializers/mysql_set_length_for_binary_indexes.rb index 1b16b39d517..81ed2fb83de 100644 --- a/config/initializers/mysql_set_length_for_binary_indexes.rb +++ b/config/initializers/mysql_set_length_for_binary_indexes.rb @@ -7,11 +7,12 @@ # the old Rails 4 schema layout is still used module MysqlSetLengthForBinaryIndex def add_index(table_name, column_names, options = {}) + options[:length] ||= {} Array(column_names).each do |column_name| column = ActiveRecord::Base.connection.columns(table_name).find { |c| c.name == column_name } if column&.type == :binary - options[:length] = 20 + options[:length][column_name] = 20 end end @@ -27,11 +28,12 @@ if Gitlab.rails5? module MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema # This method is used in Rails 5 schema loading as t.index def index(column_names, options = {}) + options[:length] ||= {} Array(column_names).each do |column_name| column = columns.find { |c| c.name == column_name } if column&.type == :binary - options[:length] = 20 + options[:length][column_name] = 20 end end -- cgit v1.2.1