diff options
Diffstat (limited to 'lib/gitlab/background_migration')
65 files changed, 184 insertions, 71 deletions
diff --git a/lib/gitlab/background_migration/add_primary_email_to_emails_if_user_confirmed.rb b/lib/gitlab/background_migration/add_primary_email_to_emails_if_user_confirmed.rb deleted file mode 100644 index b39c0953fb1..00000000000 --- a/lib/gitlab/background_migration/add_primary_email_to_emails_if_user_confirmed.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module BackgroundMigration - # Add user primary email to emails table if confirmed - class AddPrimaryEmailToEmailsIfUserConfirmed - INNER_BATCH_SIZE = 1_000 - - # Stubbed class to access the User table - class User < ActiveRecord::Base - include ::EachBatch - - self.table_name = 'users' - self.inheritance_column = :_type_disabled - - scope :confirmed, -> { where.not(confirmed_at: nil) } - - has_many :emails - end - - # Stubbed class to access the Emails table - class Email < ActiveRecord::Base - self.table_name = 'emails' - self.inheritance_column = :_type_disabled - - belongs_to :user - end - - def perform(start_id, end_id) - User.confirmed.where(id: start_id..end_id).select(:id, :email, :confirmed_at).each_batch(of: INNER_BATCH_SIZE) do |users| - current_time = Time.now.utc - - attributes = users.map do |user| - { - user_id: user.id, - email: user.email, - confirmed_at: user.confirmed_at, - created_at: current_time, - updated_at: current_time - } - end - - Email.insert_all(attributes) - end - mark_job_as_succeeded(start_id, end_id) - end - - private - - def mark_job_as_succeeded(*arguments) - Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded( - 'AddPrimaryEmailToEmailsIfUserConfirmed', - arguments - ) - end - end - end -end diff --git a/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens.rb b/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens.rb new file mode 100644 index 00000000000..82e607ac7a7 --- /dev/null +++ b/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Backfill `admin_mode` scope for a range of personal access tokens + class BackfillAdminModeScopeForPersonalAccessTokens < ::Gitlab::BackgroundMigration::BatchedMigrationJob + scope_to ->(relation) do + relation.joins('INNER JOIN users ON personal_access_tokens.user_id = users.id') + .where(users: { admin: true }) + .where(revoked: [false, nil]) + .where.not('expires_at IS NOT NULL AND expires_at <= ?', Time.current) + end + + operation_name :update_all + feature_category :authentication_and_authorization + + ADMIN_MODE_SCOPE = ['admin_mode'].freeze + + def perform + each_sub_batch do |sub_batch| + sub_batch.each do |token| + token.update!(scopes: (YAML.safe_load(token.scopes) + ADMIN_MODE_SCOPE).uniq.to_yaml) + end + end + end + end + end +end diff --git a/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities.rb b/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities.rb index 249c9d7af57..1dca82486ac 100644 --- a/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities.rb +++ b/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities.rb @@ -17,6 +17,7 @@ module Gitlab end operation_name :update_all + feature_category :database def perform each_sub_batch(batching_scope: RELATION) do |sub_batch| diff --git a/lib/gitlab/background_migration/backfill_environment_tiers.rb b/lib/gitlab/background_migration/backfill_environment_tiers.rb index 6f381577274..ebfabf1b28e 100644 --- a/lib/gitlab/background_migration/backfill_environment_tiers.rb +++ b/lib/gitlab/background_migration/backfill_environment_tiers.rb @@ -7,6 +7,7 @@ module Gitlab # See https://gitlab.com/gitlab-org/gitlab/-/issues/300741 for more information. class BackfillEnvironmentTiers < BatchedMigrationJob operation_name :backfill_environment_tiers + feature_category :database # Equivalent to `Environment#guess_tier` pattern matching. PRODUCTION_TIER = 0 diff --git a/lib/gitlab/background_migration/backfill_epic_cache_counts.rb b/lib/gitlab/background_migration/backfill_epic_cache_counts.rb index bd61d1a0f07..ee64a8ca2d5 100644 --- a/lib/gitlab/background_migration/backfill_epic_cache_counts.rb +++ b/lib/gitlab/background_migration/backfill_epic_cache_counts.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # rubocop: disable Style/Documentation class BackfillEpicCacheCounts < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + def perform; end end # rubocop: enable Style/Documentation diff --git a/lib/gitlab/background_migration/backfill_group_features.rb b/lib/gitlab/background_migration/backfill_group_features.rb index 4ea664e2529..c45dcad5b2d 100644 --- a/lib/gitlab/background_migration/backfill_group_features.rb +++ b/lib/gitlab/background_migration/backfill_group_features.rb @@ -6,6 +6,7 @@ module Gitlab class BackfillGroupFeatures < ::Gitlab::BackgroundMigration::BatchedMigrationJob job_arguments :batch_size operation_name :upsert_group_features + feature_category :database def perform each_sub_batch( diff --git a/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb b/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb index c95fed512c9..8c151bc36ac 100644 --- a/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb +++ b/lib/gitlab/background_migration/backfill_imported_issue_search_data.rb @@ -10,6 +10,7 @@ module Gitlab SUB_BATCH_SIZE = 1_000 operation_name :update_search_data + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/backfill_internal_on_notes.rb b/lib/gitlab/background_migration/backfill_internal_on_notes.rb index fe05b4ec3c1..2202cbb2f85 100644 --- a/lib/gitlab/background_migration/backfill_internal_on_notes.rb +++ b/lib/gitlab/background_migration/backfill_internal_on_notes.rb @@ -6,6 +6,7 @@ module Gitlab class BackfillInternalOnNotes < BatchedMigrationJob scope_to -> (relation) { relation.where(confidential: true) } operation_name :update_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/backfill_namespace_details.rb b/lib/gitlab/background_migration/backfill_namespace_details.rb index 640d9379351..57254c09f78 100644 --- a/lib/gitlab/background_migration/backfill_namespace_details.rb +++ b/lib/gitlab/background_migration/backfill_namespace_details.rb @@ -5,6 +5,7 @@ module Gitlab # Backfill namespace_details for a range of namespaces class BackfillNamespaceDetails < ::Gitlab::BackgroundMigration::BatchedMigrationJob operation_name :backfill_namespace_details + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads.rb b/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads.rb index dca7f9fa921..8600510b6ef 100644 --- a/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads.rb +++ b/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads.rb @@ -5,6 +5,7 @@ module Gitlab # Sets the `namespace_id` of the existing `vulnerability_reads` records class BackfillNamespaceIdOfVulnerabilityReads < BatchedMigrationJob operation_name :set_namespace_id + feature_category :database UPDATE_SQL = <<~SQL UPDATE diff --git a/lib/gitlab/background_migration/backfill_project_feature_package_registry_access_level.rb b/lib/gitlab/background_migration/backfill_project_feature_package_registry_access_level.rb index 6520cd63711..ff20a7ed177 100644 --- a/lib/gitlab/background_migration/backfill_project_feature_package_registry_access_level.rb +++ b/lib/gitlab/background_migration/backfill_project_feature_package_registry_access_level.rb @@ -18,6 +18,7 @@ module Gitlab end operation_name :update_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/backfill_project_import_level.rb b/lib/gitlab/background_migration/backfill_project_import_level.rb index 21c239e0070..1a4b1e6731f 100644 --- a/lib/gitlab/background_migration/backfill_project_import_level.rb +++ b/lib/gitlab/background_migration/backfill_project_import_level.rb @@ -4,6 +4,7 @@ module Gitlab module BackgroundMigration class BackfillProjectImportLevel < BatchedMigrationJob operation_name :update_import_level + feature_category :database LEVEL = { Gitlab::Access::NO_ACCESS => [0], diff --git a/lib/gitlab/background_migration/backfill_project_member_namespace_id.rb b/lib/gitlab/background_migration/backfill_project_member_namespace_id.rb index c2e37269b5e..1bf029f5001 100644 --- a/lib/gitlab/background_migration/backfill_project_member_namespace_id.rb +++ b/lib/gitlab/background_migration/backfill_project_member_namespace_id.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # Backfills the `members.member_namespace_id` column for `type=ProjectMember` class BackfillProjectMemberNamespaceId < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + def perform parent_batch_relation = relation_scoped_to_range(batch_table, batch_column, start_id, end_id) diff --git a/lib/gitlab/background_migration/backfill_project_namespace_details.rb b/lib/gitlab/background_migration/backfill_project_namespace_details.rb index 9bee3cf21e8..4f4db50321d 100644 --- a/lib/gitlab/background_migration/backfill_project_namespace_details.rb +++ b/lib/gitlab/background_migration/backfill_project_namespace_details.rb @@ -4,6 +4,7 @@ module Gitlab # Backfill project namespace_details for a range of projects class BackfillProjectNamespaceDetails < ::Gitlab::BackgroundMigration::BatchedMigrationJob operation_name :backfill_project_namespace_details + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/backfill_project_namespace_on_issues.rb b/lib/gitlab/background_migration/backfill_project_namespace_on_issues.rb index 34dd3321125..0c4953486f4 100644 --- a/lib/gitlab/background_migration/backfill_project_namespace_on_issues.rb +++ b/lib/gitlab/background_migration/backfill_project_namespace_on_issues.rb @@ -7,6 +7,7 @@ module Gitlab MAX_UPDATE_RETRIES = 3 operation_name :update_all + feature_category :database def perform each_sub_batch( diff --git a/lib/gitlab/background_migration/backfill_project_statistics_container_repository_size.rb b/lib/gitlab/background_migration/backfill_project_statistics_container_repository_size.rb index ec813022b8f..01cae3e2d50 100644 --- a/lib/gitlab/background_migration/backfill_project_statistics_container_repository_size.rb +++ b/lib/gitlab/background_migration/backfill_project_statistics_container_repository_size.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # Back-fill container_registry_size for project_statistics class BackfillProjectStatisticsContainerRepositorySize < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + def perform # no-op end diff --git a/lib/gitlab/background_migration/backfill_project_statistics_storage_size_without_uploads_size.rb b/lib/gitlab/background_migration/backfill_project_statistics_storage_size_without_uploads_size.rb index 1a3dd88ea31..da865ed935a 100644 --- a/lib/gitlab/background_migration/backfill_project_statistics_storage_size_without_uploads_size.rb +++ b/lib/gitlab/background_migration/backfill_project_statistics_storage_size_without_uploads_size.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # Back-fill storage_size for project_statistics class BackfillProjectStatisticsStorageSizeWithoutUploadsSize < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + def perform # no-op end diff --git a/lib/gitlab/background_migration/backfill_releases_author_id.rb b/lib/gitlab/background_migration/backfill_releases_author_id.rb new file mode 100644 index 00000000000..8982fe1acca --- /dev/null +++ b/lib/gitlab/background_migration/backfill_releases_author_id.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Backfills releases with empty release authors. + # More details on: + # 1) https://gitlab.com/groups/gitlab-org/-/epics/8375 + # 2) https://gitlab.com/gitlab-org/gitlab/-/issues/367522#note_1156503600 + class BackfillReleasesAuthorId < BatchedMigrationJob + operation_name :backfill_releases_author_id + job_arguments :ghost_user_id + feature_category :database + + scope_to ->(relation) { relation.where(author_id: nil) } + + def perform + each_sub_batch do |sub_batch| + sub_batch.update_all(author_id: ghost_user_id) + end + end + end + end +end diff --git a/lib/gitlab/background_migration/backfill_user_details_fields.rb b/lib/gitlab/background_migration/backfill_user_details_fields.rb index 8d8619256b0..26489d06a85 100644 --- a/lib/gitlab/background_migration/backfill_user_details_fields.rb +++ b/lib/gitlab/background_migration/backfill_user_details_fields.rb @@ -11,6 +11,7 @@ module Gitlab # * organization class BackfillUserDetailsFields < BatchedMigrationJob operation_name :backfill_user_details_fields + feature_category :database def perform query = <<~SQL diff --git a/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb b/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb index 37b1a37569b..20c3c68ec40 100644 --- a/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb +++ b/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb @@ -5,6 +5,7 @@ module Gitlab # Backfills the `vulnerability_reads.casted_cluster_agent_id` column class BackfillVulnerabilityReadsClusterAgent < Gitlab::BackgroundMigration::BatchedMigrationJob operation_name :update_all + feature_category :database CLUSTER_AGENTS_JOIN = <<~SQL INNER JOIN cluster_agents diff --git a/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues.rb b/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues.rb index a020cabd1f4..fc0d0ce3a57 100644 --- a/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues.rb +++ b/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues.rb @@ -5,6 +5,8 @@ module Gitlab # Backfills the `issues.work_item_type_id` column, replacing any # instances of `NULL` with the appropriate `work_item_types.id` based on `issues.issue_type` class BackfillWorkItemTypeIdForIssues < BatchedMigrationJob + feature_category :database + # Basic AR model for issues table class MigrationIssue < ApplicationRecord self.table_name = 'issues' diff --git a/lib/gitlab/background_migration/batched_migration_job.rb b/lib/gitlab/background_migration/batched_migration_job.rb index 973ab20f547..4039a79cfa7 100644 --- a/lib/gitlab/background_migration/batched_migration_job.rb +++ b/lib/gitlab/background_migration/batched_migration_job.rb @@ -27,7 +27,7 @@ module Gitlab end def operation_name(operation) - define_method('operation_name') do + define_method(:operation_name) do operation end end diff --git a/lib/gitlab/background_migration/cleanup_orphaned_routes.rb b/lib/gitlab/background_migration/cleanup_orphaned_routes.rb index 0cd19dc5df9..5c0ddf0ba8b 100644 --- a/lib/gitlab/background_migration/cleanup_orphaned_routes.rb +++ b/lib/gitlab/background_migration/cleanup_orphaned_routes.rb @@ -8,6 +8,8 @@ module Gitlab class CleanupOrphanedRoutes < Gitlab::BackgroundMigration::BatchedMigrationJob include Gitlab::Database::DynamicModelHelpers + feature_category :database + def perform # there should really be no records to fix, there is none gitlab.com, but taking the safer route, just in case. fix_missing_namespace_id_routes diff --git a/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb b/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb index 136293242b2..033b2c87152 100644 --- a/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb +++ b/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb @@ -16,6 +16,7 @@ module Gitlab class CopyColumnUsingBackgroundMigrationJob < BatchedMigrationJob job_arguments :copy_from, :copy_to operation_name :update_all + feature_category :database def perform assignment_clauses = build_assignment_clauses(copy_from, copy_to) diff --git a/lib/gitlab/background_migration/delete_approval_rules_with_vulnerability.rb b/lib/gitlab/background_migration/delete_approval_rules_with_vulnerability.rb index 739197898d9..c7c063e8ccf 100644 --- a/lib/gitlab/background_migration/delete_approval_rules_with_vulnerability.rb +++ b/lib/gitlab/background_migration/delete_approval_rules_with_vulnerability.rb @@ -5,6 +5,8 @@ module Gitlab # This class doesn't delete approval rules # as this feature exists only in EE class DeleteApprovalRulesWithVulnerability < BatchedMigrationJob + feature_category :database + def perform end end diff --git a/lib/gitlab/background_migration/delete_invalid_epic_issues.rb b/lib/gitlab/background_migration/delete_invalid_epic_issues.rb index 3af59ab4931..6c0eb6b1950 100644 --- a/lib/gitlab/background_migration/delete_invalid_epic_issues.rb +++ b/lib/gitlab/background_migration/delete_invalid_epic_issues.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # rubocop: disable Style/Documentation class DeleteInvalidEpicIssues < BatchedMigrationJob + feature_category :database + def perform end end diff --git a/lib/gitlab/background_migration/delete_orphaned_operational_vulnerabilities.rb b/lib/gitlab/background_migration/delete_orphaned_operational_vulnerabilities.rb index f93dcf83c49..6953ae65651 100644 --- a/lib/gitlab/background_migration/delete_orphaned_operational_vulnerabilities.rb +++ b/lib/gitlab/background_migration/delete_orphaned_operational_vulnerabilities.rb @@ -17,6 +17,8 @@ module Gitlab SQL operation_name :delete_orphaned_operational_vulnerabilities + feature_category :database + scope_to ->(relation) do relation .where(report_type: [REPORT_TYPES[:cluster_image_scanning], REPORT_TYPES[:custom]]) diff --git a/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb b/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb index 4b7b7d42c77..e77d56d68cb 100644 --- a/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb +++ b/lib/gitlab/background_migration/delete_orphans_approval_merge_request_rules.rb @@ -7,6 +7,7 @@ module Gitlab scope_to ->(relation) { relation.where(report_type: 4) } operation_name :delete_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/delete_orphans_approval_project_rules.rb b/lib/gitlab/background_migration/delete_orphans_approval_project_rules.rb index 33aa1a8d29d..28809df8694 100644 --- a/lib/gitlab/background_migration/delete_orphans_approval_project_rules.rb +++ b/lib/gitlab/background_migration/delete_orphans_approval_project_rules.rb @@ -5,6 +5,7 @@ module Gitlab # Deletes orphans records whenever report_type equals to scan_finding (i.e., 4) class DeleteOrphansApprovalProjectRules < BatchedMigrationJob operation_name :delete_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/destroy_invalid_group_members.rb b/lib/gitlab/background_migration/destroy_invalid_group_members.rb index 9eb0d4489d6..79aae719d03 100644 --- a/lib/gitlab/background_migration/destroy_invalid_group_members.rb +++ b/lib/gitlab/background_migration/destroy_invalid_group_members.rb @@ -10,6 +10,7 @@ module Gitlab end operation_name :delete_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/destroy_invalid_members.rb b/lib/gitlab/background_migration/destroy_invalid_members.rb index b274c71f24f..9a70dc39960 100644 --- a/lib/gitlab/background_migration/destroy_invalid_members.rb +++ b/lib/gitlab/background_migration/destroy_invalid_members.rb @@ -5,6 +5,7 @@ module Gitlab class DestroyInvalidMembers < Gitlab::BackgroundMigration::BatchedMigrationJob # rubocop:disable Style/Documentation scope_to ->(relation) { relation.where(member_namespace_id: nil) } operation_name :delete_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/destroy_invalid_project_members.rb b/lib/gitlab/background_migration/destroy_invalid_project_members.rb index 53b4712ef6e..5f6bb840f77 100644 --- a/lib/gitlab/background_migration/destroy_invalid_project_members.rb +++ b/lib/gitlab/background_migration/destroy_invalid_project_members.rb @@ -5,6 +5,7 @@ module Gitlab class DestroyInvalidProjectMembers < Gitlab::BackgroundMigration::BatchedMigrationJob # rubocop:disable Style/Documentation scope_to ->(relation) { relation.where(source_type: 'Project') } operation_name :delete_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects.rb b/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects.rb index b32e88581dd..c4ce88b9404 100644 --- a/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects.rb +++ b/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects.rb @@ -8,6 +8,7 @@ module Gitlab THRESHOLD_DATE = '2022-02-17 09:00:00' operation_name :disable_legacy_open_source_licence_for_recent_public_projects + feature_category :database # Migration only version of `project_settings` table class ProjectSetting < ApplicationRecord diff --git a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_inactive_public_projects.rb b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_inactive_public_projects.rb index 5685b782a71..6114aa33a43 100644 --- a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_inactive_public_projects.rb +++ b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_inactive_public_projects.rb @@ -9,6 +9,7 @@ module Gitlab LAST_ACTIVITY_DATE = '2021-07-01' operation_name :disable_legacy_open_source_license_available + feature_category :database # Migration only version of `project_settings` table class ProjectSetting < ApplicationRecord diff --git a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb index b5e5555bd2d..2eb7c5230ba 100644 --- a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb +++ b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects.rb @@ -7,6 +7,7 @@ module Gitlab PUBLIC = 20 operation_name :disable_legacy_open_source_license_for_no_issues_no_repo_projects + feature_category :database # Migration only version of `project_settings` table class ProjectSetting < ApplicationRecord diff --git a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects.rb b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects.rb index 89863458676..8953836c705 100644 --- a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects.rb +++ b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects.rb @@ -7,6 +7,7 @@ module Gitlab PUBLIC = 20 operation_name :disable_legacy_open_source_license_for_one_member_no_repo_projects + feature_category :database # Migration only version of `project_settings` table class ProjectSetting < ApplicationRecord diff --git a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb.rb b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb.rb index dcef4f086e2..b2805289b30 100644 --- a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb.rb +++ b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb.rb @@ -10,6 +10,7 @@ module Gitlab end operation_name :disable_legacy_open_source_license_for_projects_less_than_five_mb + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb.rb b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb.rb index 7d93f2d4fda..15c80a6cac2 100644 --- a/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb.rb +++ b/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb.rb @@ -6,6 +6,7 @@ module Gitlab class DisableLegacyOpenSourceLicenseForProjectsLessThanOneMb < ::Gitlab::BackgroundMigration::BatchedMigrationJob scope_to ->(relation) { relation.where(legacy_open_source_license_available: true) } operation_name :disable_legacy_open_source_license_for_projects_less_than_one_mb + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/expire_o_auth_tokens.rb b/lib/gitlab/background_migration/expire_o_auth_tokens.rb index 08bcdb8a789..20dacd642de 100644 --- a/lib/gitlab/background_migration/expire_o_auth_tokens.rb +++ b/lib/gitlab/background_migration/expire_o_auth_tokens.rb @@ -4,21 +4,15 @@ module Gitlab module BackgroundMigration # Add expiry to all OAuth access tokens class ExpireOAuthTokens < ::Gitlab::BackgroundMigration::BatchedMigrationJob - operation_name :update_oauth_tokens + scope_to ->(relation) { relation.where(expires_in: nil) } + operation_name :update_all + feature_category :database def perform - each_sub_batch( - batching_scope: ->(relation) { relation.where(expires_in: nil) } - ) do |sub_batch| - update_oauth_tokens(sub_batch) + each_sub_batch do |sub_batch| + sub_batch.update_all(expires_in: 2.hours) end end - - private - - def update_oauth_tokens(relation) - relation.update_all(expires_in: 7_200) - end end end end diff --git a/lib/gitlab/background_migration/fix_approval_project_rules_without_protected_branches.rb b/lib/gitlab/background_migration/fix_approval_project_rules_without_protected_branches.rb index 4b283bae79d..bfbed0408e1 100644 --- a/lib/gitlab/background_migration/fix_approval_project_rules_without_protected_branches.rb +++ b/lib/gitlab/background_migration/fix_approval_project_rules_without_protected_branches.rb @@ -5,6 +5,8 @@ module Gitlab # This class doesn't update approval project rules # as this feature exists only in EE class FixApprovalProjectRulesWithoutProtectedBranches < BatchedMigrationJob + feature_category :database + def perform; end end end diff --git a/lib/gitlab/background_migration/fix_projects_without_prometheus_service.rb b/lib/gitlab/background_migration/fix_projects_without_prometheus_service.rb index 97a9913fa74..452167d4d61 100644 --- a/lib/gitlab/background_migration/fix_projects_without_prometheus_service.rb +++ b/lib/gitlab/background_migration/fix_projects_without_prometheus_service.rb @@ -186,7 +186,7 @@ module Gitlab end def migrate_instance_cluster? - if instance_variable_defined?('@migrate_instance_cluster') + if instance_variable_defined?(:@migrate_instance_cluster) @migrate_instance_cluster else @migrate_instance_cluster = Migratable::Cluster.instance_type.has_prometheus_application? diff --git a/lib/gitlab/background_migration/fix_security_scan_statuses.rb b/lib/gitlab/background_migration/fix_security_scan_statuses.rb index b60e739f870..1cfc9a278b7 100644 --- a/lib/gitlab/background_migration/fix_security_scan_statuses.rb +++ b/lib/gitlab/background_migration/fix_security_scan_statuses.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # Fixes the `status` attribute of `security_scans` records class FixSecurityScanStatuses < BatchedMigrationJob + feature_category :database + def perform # no-op. The logic is defined in EE module. end diff --git a/lib/gitlab/background_migration/migrate_shared_vulnerability_scanners.rb b/lib/gitlab/background_migration/migrate_shared_vulnerability_scanners.rb index bea0120f093..d1acb8ca2d2 100644 --- a/lib/gitlab/background_migration/migrate_shared_vulnerability_scanners.rb +++ b/lib/gitlab/background_migration/migrate_shared_vulnerability_scanners.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # rubocop: disable Style/Documentation class MigrateSharedVulnerabilityScanners < BatchedMigrationJob + feature_category :database + def perform end end diff --git a/lib/gitlab/background_migration/migrate_vulnerabilities_feedback_to_vulnerabilities_state_transition.rb b/lib/gitlab/background_migration/migrate_vulnerabilities_feedback_to_vulnerabilities_state_transition.rb index 81b29b5a6cd..84f7462e6b8 100644 --- a/lib/gitlab/background_migration/migrate_vulnerabilities_feedback_to_vulnerabilities_state_transition.rb +++ b/lib/gitlab/background_migration/migrate_vulnerabilities_feedback_to_vulnerabilities_state_transition.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration class MigrateVulnerabilitiesFeedbackToVulnerabilitiesStateTransition < BatchedMigrationJob + feature_category :database + def perform; end end end diff --git a/lib/gitlab/background_migration/populate_approval_merge_request_rules_with_security_orchestration.rb b/lib/gitlab/background_migration/populate_approval_merge_request_rules_with_security_orchestration.rb index 2257dc016be..00d7b1b9664 100644 --- a/lib/gitlab/background_migration/populate_approval_merge_request_rules_with_security_orchestration.rb +++ b/lib/gitlab/background_migration/populate_approval_merge_request_rules_with_security_orchestration.rb @@ -5,6 +5,8 @@ module Gitlab # This class doesn't delete merge request level rules # as this feature exists only in EE class PopulateApprovalMergeRequestRulesWithSecurityOrchestration < BatchedMigrationJob + feature_category :database + def perform; end end end diff --git a/lib/gitlab/background_migration/populate_approval_project_rules_with_security_orchestration.rb b/lib/gitlab/background_migration/populate_approval_project_rules_with_security_orchestration.rb index 1d0c0010551..e5f283db926 100644 --- a/lib/gitlab/background_migration/populate_approval_project_rules_with_security_orchestration.rb +++ b/lib/gitlab/background_migration/populate_approval_project_rules_with_security_orchestration.rb @@ -5,6 +5,8 @@ module Gitlab # This class doesn't delete merge request level rules # as this feature exists only in EE class PopulateApprovalProjectRulesWithSecurityOrchestration < BatchedMigrationJob + feature_category :database + def perform; end end end diff --git a/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations.rb b/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations.rb index 3dd867fa1fe..46758bc8fed 100644 --- a/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations.rb +++ b/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations.rb @@ -7,6 +7,7 @@ module Gitlab # The operations_access_level setting is being split into three seperate toggles. class PopulateOperationVisibilityPermissionsFromOperations < BatchedMigrationJob operation_name :populate_operations_visibility + feature_category :database def perform each_sub_batch do |batch| diff --git a/lib/gitlab/background_migration/populate_projects_star_count.rb b/lib/gitlab/background_migration/populate_projects_star_count.rb index 085d576637e..8417dc91b1b 100644 --- a/lib/gitlab/background_migration/populate_projects_star_count.rb +++ b/lib/gitlab/background_migration/populate_projects_star_count.rb @@ -7,6 +7,7 @@ module Gitlab MAX_UPDATE_RETRIES = 3 operation_name :update_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/prune_stale_project_export_jobs.rb b/lib/gitlab/background_migration/prune_stale_project_export_jobs.rb index a91cda2c427..3b4b55276fa 100644 --- a/lib/gitlab/background_migration/prune_stale_project_export_jobs.rb +++ b/lib/gitlab/background_migration/prune_stale_project_export_jobs.rb @@ -8,6 +8,7 @@ module Gitlab scope_to ->(relation) { relation.where("updated_at < ?", EXPIRES_IN.ago) } operation_name :delete_all + feature_category :database def perform each_sub_batch(&:delete_all) diff --git a/lib/gitlab/background_migration/re_expire_o_auth_tokens.rb b/lib/gitlab/background_migration/re_expire_o_auth_tokens.rb new file mode 100644 index 00000000000..c327b14669d --- /dev/null +++ b/lib/gitlab/background_migration/re_expire_o_auth_tokens.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # rubocop: disable Style/Documentation + class ReExpireOAuthTokens < Gitlab::BackgroundMigration::ExpireOAuthTokens # rubocop:disable Migration/BackgroundMigrationBaseClass + end + # rubocop: enable Style/Documentation + end +end diff --git a/lib/gitlab/background_migration/recount_epic_cache_counts.rb b/lib/gitlab/background_migration/recount_epic_cache_counts.rb index 42f84a33a5a..cec17ef7cff 100644 --- a/lib/gitlab/background_migration/recount_epic_cache_counts.rb +++ b/lib/gitlab/background_migration/recount_epic_cache_counts.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration # rubocop: disable Style/Documentation class RecountEpicCacheCounts < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + def perform; end end # rubocop: enable Style/Documentation diff --git a/lib/gitlab/background_migration/remove_backfilled_job_artifacts_expire_at.rb b/lib/gitlab/background_migration/remove_backfilled_job_artifacts_expire_at.rb index dc7c16d7947..7b88e10f39c 100644 --- a/lib/gitlab/background_migration/remove_backfilled_job_artifacts_expire_at.rb +++ b/lib/gitlab/background_migration/remove_backfilled_job_artifacts_expire_at.rb @@ -7,6 +7,7 @@ module Gitlab # These job artifacts will not be deleted and will have their `expire_at` removed. class RemoveBackfilledJobArtifactsExpireAt < BatchedMigrationJob operation_name :update_all + feature_category :database # The migration would have backfilled `expire_at` # to midnight on the 22nd of the month of the local timezone, diff --git a/lib/gitlab/background_migration/remove_self_managed_wiki_notes.rb b/lib/gitlab/background_migration/remove_self_managed_wiki_notes.rb index a284c04d4f5..cf3897208b8 100644 --- a/lib/gitlab/background_migration/remove_self_managed_wiki_notes.rb +++ b/lib/gitlab/background_migration/remove_self_managed_wiki_notes.rb @@ -5,6 +5,7 @@ module Gitlab # Removes obsolete wiki notes class RemoveSelfManagedWikiNotes < BatchedMigrationJob operation_name :delete_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb b/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb index 1b13c2ab7ef..0615d8a6783 100644 --- a/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb +++ b/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb @@ -14,6 +14,7 @@ module Gitlab } operation_name :update_all + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_encrypted_values.rb b/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_encrypted_values.rb index 832385fd662..64eae1e934e 100644 --- a/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_encrypted_values.rb +++ b/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_encrypted_values.rb @@ -5,6 +5,7 @@ module Gitlab # A job to nullify duplicate token_encrypted values in ci_runners table in batches class ResetDuplicateCiRunnersTokenEncryptedValues < BatchedMigrationJob operation_name :nullify_duplicate_ci_runner_token_encrypted_values + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values.rb b/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values.rb index 5f552accd8d..fd15caa5644 100644 --- a/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values.rb +++ b/lib/gitlab/background_migration/reset_duplicate_ci_runners_token_values.rb @@ -5,6 +5,7 @@ module Gitlab # A job to nullify duplicate token values in ci_runners table in batches class ResetDuplicateCiRunnersTokenValues < BatchedMigrationJob operation_name :nullify_duplicate_ci_runner_token_values + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/reset_status_on_container_repositories.rb b/lib/gitlab/background_migration/reset_status_on_container_repositories.rb index 09cd3b1895f..0dbe2781327 100644 --- a/lib/gitlab/background_migration/reset_status_on_container_repositories.rb +++ b/lib/gitlab/background_migration/reset_status_on_container_repositories.rb @@ -13,6 +13,7 @@ module Gitlab scope_to ->(relation) { relation.where(status: DELETE_SCHEDULED_STATUS) } operation_name :reset_status_on_container_repositories + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/sanitize_confidential_todos.rb b/lib/gitlab/background_migration/sanitize_confidential_todos.rb index d3ef6ac3019..2df0b8a4d93 100644 --- a/lib/gitlab/background_migration/sanitize_confidential_todos.rb +++ b/lib/gitlab/background_migration/sanitize_confidential_todos.rb @@ -13,6 +13,7 @@ module Gitlab scope_to ->(relation) { relation.where(confidential: true) } operation_name :delete_invalid_todos + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/second_recount_epic_cache_counts.rb b/lib/gitlab/background_migration/second_recount_epic_cache_counts.rb new file mode 100644 index 00000000000..4d7c4a682a9 --- /dev/null +++ b/lib/gitlab/background_migration/second_recount_epic_cache_counts.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # rubocop: disable Style/Documentation + class SecondRecountEpicCacheCounts < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + + def perform; end + end + # rubocop: enable Style/Documentation + end +end + +# rubocop: disable Layout/LineLength +# we just want to re-enqueue the previous BackfillEpicCacheCounts migration, +# because it's a EE-only migation and it's a module, we just prepend new +# RecountEpicCacheCounts with existing batched migration module (which is same in both cases) +Gitlab::BackgroundMigration::SecondRecountEpicCacheCounts.prepend_mod_with('Gitlab::BackgroundMigration::BackfillEpicCacheCounts') +# rubocop: enable Layout/LineLength diff --git a/lib/gitlab/background_migration/set_correct_vulnerability_state.rb b/lib/gitlab/background_migration/set_correct_vulnerability_state.rb index dfd71bb8b5f..49ef75d7ba8 100644 --- a/lib/gitlab/background_migration/set_correct_vulnerability_state.rb +++ b/lib/gitlab/background_migration/set_correct_vulnerability_state.rb @@ -8,6 +8,7 @@ module Gitlab scope_to ->(relation) { relation.where.not(dismissed_at: nil) } operation_name :update_vulnerabilities_state + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects.rb b/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects.rb index 4ae7ad897cf..86fcfa18dc3 100644 --- a/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects.rb +++ b/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects.rb @@ -7,6 +7,7 @@ module Gitlab PUBLIC = 20 operation_name :set_legacy_open_source_license_available + feature_category :database # Migration only version of `project_settings` table class ProjectSetting < ApplicationRecord diff --git a/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles.rb b/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles.rb new file mode 100644 index 00000000000..5ae1698b910 --- /dev/null +++ b/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Truncate the Vulnerability html_title if it exceeds 800 chars + class TruncateOverlongVulnerabilityHtmlTitles < BatchedMigrationJob + feature_category :vulnerability_management + scope_to ->(relation) { relation.where("LENGTH(title_html) > 800") } + operation_name :truncate_vulnerability_title_htmls + + class Vulnerability < ApplicationRecord # rubocop:disable Style/Documentation + self.table_name = "vulnerabilities" + end + + def perform + each_sub_batch do |sub_batch| + sub_batch.update_all("title_html = left(title_html, 800)") + end + end + end + end +end diff --git a/lib/gitlab/background_migration/update_ci_pipeline_artifacts_unknown_locked_status.rb b/lib/gitlab/background_migration/update_ci_pipeline_artifacts_unknown_locked_status.rb index 84183753158..77b4a9ab7e4 100644 --- a/lib/gitlab/background_migration/update_ci_pipeline_artifacts_unknown_locked_status.rb +++ b/lib/gitlab/background_migration/update_ci_pipeline_artifacts_unknown_locked_status.rb @@ -9,6 +9,8 @@ module Gitlab # value of the associated `ci_pipelines.locked` value. This class # does an UPDATE join to make the values match. class UpdateCiPipelineArtifactsUnknownLockedStatus < BatchedMigrationJob + feature_category :database + def perform connection.exec_query(<<~SQL) UPDATE ci_pipeline_artifacts diff --git a/lib/gitlab/background_migration/update_delayed_project_removal_to_null_for_user_namespaces.rb b/lib/gitlab/background_migration/update_delayed_project_removal_to_null_for_user_namespaces.rb index b2cf8298e4f..a7faa5703da 100644 --- a/lib/gitlab/background_migration/update_delayed_project_removal_to_null_for_user_namespaces.rb +++ b/lib/gitlab/background_migration/update_delayed_project_removal_to_null_for_user_namespaces.rb @@ -11,6 +11,7 @@ module Gitlab end operation_name :set_delayed_project_removal_to_null_for_user_namespace + feature_category :database def perform each_sub_batch do |sub_batch| diff --git a/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url.rb b/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url.rb index 8aab7d13b45..6d59a5c8651 100644 --- a/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url.rb +++ b/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration class UpdateJiraTrackerDataDeploymentTypeBasedOnUrl < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + # rubocop: disable Gitlab/NamespacedClass class JiraTrackerData < ActiveRecord::Base self.table_name = "jira_tracker_data" |