diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-28 03:09:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-28 03:09:28 +0300 |
commit | 2d096b1a9b759a3e4923df4dc77dea9198ca3b09 (patch) | |
tree | 0cf18a37e85d3a57d4f2d20129e9bbc116b7701e /db | |
parent | 9da482ecb8d25c8b6387f3262cfe983976333eec (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
5 files changed, 29 insertions, 136 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 diff --git a/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb b/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb index b8f843fdd50..074ba97da65 100644 --- a/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb +++ b/db/post_migrate/20210816183304_schedule_copy_ci_builds_columns_to_security_scans2.rb @@ -1,32 +1,8 @@ # frozen_string_literal: true class ScheduleCopyCiBuildsColumnsToSecurityScans2 < ActiveRecord::Migration[6.1] - include Gitlab::Database::MigrationHelpers - - INTERVAL = 2.minutes.to_i - BATCH_SIZE = 5_000 - MIGRATION = 'CopyCiBuildsColumnsToSecurityScans' - - disable_ddl_transaction! - - class SecurityScan < ActiveRecord::Base - include EachBatch - - self.table_name = 'security_scans' - end - def up - SecurityScan.reset_column_information - - delete_job_tracking(MIGRATION, status: %w[pending succeeded]) - - queue_background_migration_jobs_by_range_at_intervals( - SecurityScan, - MIGRATION, - INTERVAL, - batch_size: BATCH_SIZE, - track_jobs: true - ) + # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database end def down diff --git a/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb b/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb index 2e6ad12f928..3a758394d7f 100644 --- a/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb +++ b/db/post_migrate/20210908132335_disable_job_token_scope_when_unused.rb @@ -1,52 +1,11 @@ # frozen_string_literal: true class DisableJobTokenScopeWhenUnused < Gitlab::Database::Migration[1.0] - disable_ddl_transaction! - - class ProjectCiCdSetting < ApplicationRecord - include EachBatch - - self.table_name = 'project_ci_cd_settings' - end - - module Ci - module JobToken - class ProjectScopeLink < ApplicationRecord - self.table_name = 'ci_job_token_project_scope_links' - end - end - end - def up - # Disabling job token scope after db/migrate/20210902171808_set_default_job_token_scope_false.rb - # if users haven't configured it. - ProjectCiCdSetting.each_batch(of: 10_000) do |settings| - with_enabled_but_unused_scope(settings).each_batch(of: 500) do |settings_to_update| - settings_to_update.update_all(job_token_scope_enabled: false) - end - end + # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database end def down - # irreversible data migration - - # The migration relies on the state of `job_token_scope_enabled` and - # updates it based on whether the feature is used or not. - # - # The inverse migration would be to set `job_token_scope_enabled: true` - # for those projects that have the feature disabled and unused. But there - # could be also existing cases where the feature is disabled and unused. - # For example, old projects. - end - - private - - # The presence of ProjectScopeLinks means that the job token scope - # is configured and we need to leave it enabled. Unused job token scope - # can be disabled since they weren't configured. - def with_enabled_but_unused_scope(settings) - settings - .where(job_token_scope_enabled: true) - .where.not(project_id: Ci::JobToken::ProjectScopeLink.select(:source_project_id)) + # no-op end end diff --git a/db/post_migrate/20220722145845_schedule_backfilling_the_namespace_id_for_vulnerability_reads.rb b/db/post_migrate/20220722145845_schedule_backfilling_the_namespace_id_for_vulnerability_reads.rb new file mode 100644 index 00000000000..e2d1846f8f6 --- /dev/null +++ b/db/post_migrate/20220722145845_schedule_backfilling_the_namespace_id_for_vulnerability_reads.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ScheduleBackfillingTheNamespaceIdForVulnerabilityReads < Gitlab::Database::Migration[2.0] + MIGRATION_NAME = 'BackfillNamespaceIdOfVulnerabilityReads' + + restrict_gitlab_migration gitlab_schema: :gitlab_main + disable_ddl_transaction! + + def up + queue_batched_background_migration( + MIGRATION_NAME, + :vulnerability_reads, + :vulnerability_id, + job_interval: 2.minutes, + batch_size: 10_000, + sub_batch_size: 200 + ) + end + + def down + delete_batched_background_migration(MIGRATION_NAME, :vulnerability_reads, :vulnerability_id, []) + end +end diff --git a/db/schema_migrations/20220722145845 b/db/schema_migrations/20220722145845 new file mode 100644 index 00000000000..458facc060d --- /dev/null +++ b/db/schema_migrations/20220722145845 @@ -0,0 +1 @@ +612a9cf3004e4d837749ef522ed72920275c9ddd8570b1a5a5e6ff51b49afd67
\ No newline at end of file |