diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-25 11:02:13 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:46:03 +0300 |
commit | ce4e0837c4ce11ad31c7be487d08bf44d961ec6f (patch) | |
tree | 41e9b06eded1475c5d01bb677933f627c7b52a5c /config/initializers | |
parent | eda001565c5afbf6e2eb9b8b5cf4fa9d6525ed71 (diff) |
mysql hack: set length for binary indexes
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/mysql_set_length_for_binary_indexes.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/config/initializers/mysql_set_length_for_binary_indexes.rb b/config/initializers/mysql_set_length_for_binary_indexes.rb new file mode 100644 index 00000000000..b5c6e39f6a8 --- /dev/null +++ b/config/initializers/mysql_set_length_for_binary_indexes.rb @@ -0,0 +1,25 @@ +# 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_names, options = {}) + 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 + end + end + + __gitlab_add_index2(table_name, column_names, options) + end + end + end + end +end |