diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-07-27 18:29:39 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-07-27 18:29:39 +0300 |
commit | ac0cbe69706a2d3013d37adda7514824a2d06ed4 (patch) | |
tree | 7730163984394f4e79711c609a2d1da2bb4f807e /config/initializers | |
parent | 9981814514742a2ee507d4dcc2fd71099fd96585 (diff) | |
parent | 5ebccab1eb74f7bf9f7f9d4f2d9a56fb81754cbe (diff) |
Merge branch 'feature/gpg-signed-commits' into 'master'
GPG signed commits
Closes #20268
See merge request !9546
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/mysql_set_length_for_binary_indexes.rb | 21 |
1 files changed, 21 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..de0bc5322aa --- /dev/null +++ b/config/initializers/mysql_set_length_for_binary_indexes.rb @@ -0,0 +1,21 @@ +# 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. + +module MysqlSetLengthForBinaryIndex + 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 + + super(table_name, column_names, options) + end +end + +if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) + ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(:prepend, MysqlSetLengthForBinaryIndex) +end |