diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-30 12:09:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-30 12:09:35 +0300 |
commit | bf774d67fc8a84f76f20494c318d7cfacb0c69ac (patch) | |
tree | b991cad6b68560d19f8ce3075577aab2eb51fae6 /app/services/concerns | |
parent | 50f0475ee134da9ea12e758a9f3250f2ab19cd65 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/concerns')
-rw-r--r-- | app/services/concerns/integrations/bulk_operation_hashes.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/services/concerns/integrations/bulk_operation_hashes.rb b/app/services/concerns/integrations/bulk_operation_hashes.rb new file mode 100644 index 00000000000..3f13c764ebe --- /dev/null +++ b/app/services/concerns/integrations/bulk_operation_hashes.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# Returns hashes of attributes suitable for passing to `.insert_all` or `update_all` +module Integrations + module BulkOperationHashes + private + + def integration_hash(operation) + integration + .to_database_hash + .merge('inherit_from_id' => integration.inherit_from_id || integration.id) + .merge(update_timestamps(operation)) + end + + def data_fields_hash(operation) + integration + .data_fields + .to_database_hash + .merge(update_timestamps(operation)) + end + + def update_timestamps(operation) + time_now = Time.current + + { + 'created_at' => (time_now if operation == :create), + 'updated_at' => time_now + }.compact + end + end +end |