summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-07-25 10:02:13 +0200
committerAlexis Reigel <mail@koffeinfrei.org>2017-07-27 15:46:03 +0200
commitce4e0837c4ce11ad31c7be487d08bf44d961ec6f (patch)
tree41e9b06eded1475c5d01bb677933f627c7b52a5c
parenteda001565c5afbf6e2eb9b8b5cf4fa9d6525ed71 (diff)
downloadgitlab-ce-ce4e0837c4ce11ad31c7be487d08bf44d961ec6f.tar.gz
mysql hack: set length for binary indexes
-rw-r--r--config/initializers/mysql_set_length_for_binary_indexes.rb25
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