summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 18:07:48 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 18:07:48 +0000
commite20baee820ea2c76ee16980a98e8080f255d9035 (patch)
tree6e13a73bee42b7ef310850d03982faebea17a0b1 /config
parent71c5863d7b1ca9836a7d7703f35750cd726a9846 (diff)
downloadgitlab-ce-e20baee820ea2c76ee16980a98e8080f255d9035.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'config')
-rw-r--r--config/initializers/active_record_fix_insert_all.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/config/initializers/active_record_fix_insert_all.rb b/config/initializers/active_record_fix_insert_all.rb
new file mode 100644
index 00000000000..8ae208dd0e5
--- /dev/null
+++ b/config/initializers/active_record_fix_insert_all.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+# This fix is needed to properly support
+# columns that perform data mutation to a SQL datatype
+# ex. would be `jsonb` and `enum`
+#
+# This is covered by tests in `BulkInsertSafe`
+# that validates handling of different data types
+
+if Rails.gem_version > Gem::Version.new("6.0.2")
+ raise Gem::DependencyError,
+ "Remove patch once the https://github.com/rails/rails/pull/38763 is included"
+end
+
+module ActiveRecordInsertAllBuilderMixin
+ def extract_types_from_columns_on(table_name, keys:)
+ columns = connection.schema_cache.columns_hash(table_name)
+
+ unknown_column = (keys - columns.keys).first
+ raise UnknownAttributeError.new(model.new, unknown_column) if unknown_column
+
+ keys.index_with { |key| model.type_for_attribute(key) }
+ end
+end
+
+ActiveRecord::InsertAll::Builder.prepend(ActiveRecordInsertAllBuilderMixin)