diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb')
-rw-r--r-- | db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb | 70 |
1 files changed, 2 insertions, 68 deletions
diff --git a/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb b/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb index 5db39334550..14b6b9efad3 100644 --- a/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb +++ b/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb @@ -1,77 +1,11 @@ # frozen_string_literal: true class AssociateExistingDastBuildsWithVariables < ActiveRecord::Migration[6.1] - disable_ddl_transaction! - - class Profile < ApplicationRecord - self.table_name = 'dast_profiles' - self.inheritance_column = :_type_disabled - end - - class ProfilesPipeline < ApplicationRecord - include EachBatch - - self.table_name = 'dast_profiles_pipelines' - self.inheritance_column = :_type_disabled - - belongs_to :profile, foreign_key: :dast_profile_id - end - - class Build < ApplicationRecord - self.table_name = 'ci_builds' - self.inheritance_column = :_type_disabled - - default_scope { where(name: :dast, stage: :dast) } # rubocop:disable Cop/DefaultScope - end - - class SiteProfilesBuild < ApplicationRecord - self.table_name = 'dast_site_profiles_builds' - self.inheritance_column = :_type_disabled - end - - BATCH_SIZE = 300 - def up - process_batch do |batch| - bulk_inserts = [] - - grouped_builds = fetch_builds(batch).group_by(&:commit_id) - - batch.includes(:profile).each do |profile_pipeline| - builds = grouped_builds[profile_pipeline.ci_pipeline_id] - - next if builds.blank? - - builds.each do |build| - bulk_inserts.push(dast_site_profile_id: profile_pipeline.profile.dast_site_profile_id, ci_build_id: build.id) - end - end - - SiteProfilesBuild.insert_all(bulk_inserts, unique_by: :ci_build_id) - end + # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database end def down - process_batch do |batch| - builds = fetch_builds(batch) - - SiteProfilesBuild - .where(ci_build_id: builds) - .delete_all - end - end - - private - - def fetch_builds(batch) - # pluck necessary to support ci table decomposition - # https://gitlab.com/groups/gitlab-org/-/epics/6289 - Build.where(commit_id: batch.pluck(:ci_pipeline_id)) - end - - def process_batch - ProfilesPipeline.each_batch(of: BATCH_SIZE, column: :ci_pipeline_id) do |batch| - yield(batch) - end + # No-op end end |