Class: Gitlab::BackgroundMigration::BackfillDesiredShardingKeyJob

Inherits:
BatchedMigrationJob show all
Defined in:
lib/gitlab/background_migration/backfill_desired_sharding_key_job.rb

Overview

rubocop: disable BackgroundMigration/FeatureCategory – Feature category to be specified by inheriting class

Direct Known Subclasses

BackfillAgentActivityEventsAgentProjectId, BackfillAlertManagementAlertAssigneesProjectId, BackfillAlertManagementAlertMetricImagesProjectId, BackfillAlertManagementAlertUserMentionsProjectId, BackfillApprovalGroupRulesProtectedBranchesGroupId, BackfillApprovalGroupRulesUsersGroupId, BackfillApprovalMergeRequestRuleSourcesProjectId, BackfillApprovalMergeRequestRulesProjectId, BackfillApprovalProjectRulesProtectedBranchesProjectId, BackfillApprovalProjectRulesUsersProjectId, BackfillApprovalsProjectId, BackfillAuditEventsStreamingEventTypeFiltersGroupId, BackfillAuditEventsStreamingHeadersGroupId, BackfillBoardsEpicBoardLabelsGroupId, BackfillBoardsEpicBoardPositionsGroupId, BackfillBoardsEpicListsGroupId, BackfillBoardsEpicUserPreferencesGroupId, BackfillCiBuildsRunnerSessionProjectId, BackfillCiJobArtifactStatesProjectId, BackfillCiJobVariablesProjectId, BackfillCiPipelineScheduleVariablesProjectId, BackfillCiResourcesProjectId, BackfillCiSecureFileStatesProjectId, BackfillCiTriggerRequestsProjectId, BackfillCiUnitTestFailuresProjectId, BackfillClusterAgentTokensProjectId, BackfillComplianceFrameworkSecurityPoliciesNamespaceId, BackfillComplianceFrameworkSecurityPoliciesProjectId, BackfillContainerRepositoryStatesProjectId, BackfillDastPreScanVerificationsProjectId, BackfillDastProfilesPipelinesProjectId, BackfillDastProfilesTagsProjectId, BackfillDastScannerProfilesBuildsProjectId, BackfillDastSiteProfileSecretVariablesProjectId, BackfillDastSiteProfilesBuildsProjectId, BackfillDastSiteValidationsProjectId, BackfillDependencyProxyBlobStatesGroupId, BackfillDependencyProxyManifestStatesGroupId, BackfillDeploymentApprovalsProjectId, BackfillDesignManagementDesignsNamespaceId, BackfillDesignManagementRepositoriesNamespaceId, BackfillDesignManagementVersionsNamespaceId, BackfillDesiredShardingKeyPartitionJob, BackfillDoraDailyMetricsProjectId, BackfillDraftNotesProjectId, BackfillEpicIssuesNamespaceId, BackfillEpicUserMentionsGroupId, BackfillErrorTrackingErrorEventsProjectId, BackfillEvidencesProjectId, BackfillExternalStatusChecksProtectedBranchesProjectId, BackfillGroupWikiRepositoryStatesGroupId, BackfillIncidentManagementEscalationRulesProjectId, BackfillIncidentManagementIssuableEscalationStatusesNamespaceId, BackfillIncidentManagementOncallRotationsProjectId, BackfillIncidentManagementPendingAlertEscalationsProjectId, BackfillIncidentManagementTimelineEventTagLinksProjectId, BackfillIssuableMetricImagesNamespaceId, BackfillIssuableResourceLinksNamespaceId, BackfillIssuableSeveritiesNamespaceId, BackfillIssueAssignmentEventsNamespaceId, BackfillIssueCustomerRelationsContactsNamespaceId, BackfillIssueEmailParticipantsNamespaceId, BackfillIssueEmailsNamespaceId, BackfillIssueLinksNamespaceId, BackfillIssueMetricsNamespaceId, BackfillIssueUserMentionsNamespaceId, BackfillMergeRequestAssigneesProjectId, BackfillMergeRequestAssignmentEventsProjectId, BackfillMergeRequestBlocksProjectId, BackfillMergeRequestContextCommitsProjectId, BackfillMergeRequestReviewLlmSummariesProjectId, BackfillMergeRequestReviewersProjectId, BackfillMergeRequestUserMentionsProjectId, BackfillMergeRequestsClosingIssuesProjectId, BackfillMilestoneReleasesProjectId, BackfillMlCandidateMetadataProjectId, BackfillMlCandidateMetricsProjectId, BackfillMlCandidateParamsProjectId, BackfillMlExperimentMetadataProjectId, BackfillMlModelMetadataProjectId, BackfillOperationsFeatureFlagsIssuesProjectId, BackfillOperationsStrategiesProjectId, BackfillOperationsStrategiesUserListsProjectId, BackfillPackagesBuildInfosProjectId, BackfillPackagesComposerMetadataProjectId, BackfillPackagesConanMetadataProjectId, BackfillPackagesDebianGroupArchitecturesGroupId, BackfillPackagesDebianGroupComponentsGroupId, BackfillPackagesDebianGroupDistributionKeysGroupId, BackfillPackagesDebianProjectArchitecturesProjectId, BackfillPackagesDebianProjectComponentsProjectId, BackfillPackagesDebianProjectDistributionKeysProjectId, BackfillPackagesDebianPublicationsProjectId, BackfillPackagesDependencyLinksProjectId, BackfillPackagesMavenMetadataProjectId, BackfillPackagesNpmMetadataProjectId, BackfillPackagesNugetMetadataProjectId, BackfillPackagesNugetSymbolsProjectId, BackfillPackagesPackageFilesProjectId, BackfillPackagesPypiMetadataProjectId, BackfillPackagesRpmMetadataProjectId, BackfillPackagesRubygemsMetadataProjectId, BackfillPagesDeploymentStatesProjectId, BackfillPagesDomainAcmeOrdersProjectId, BackfillProjectRelationExportsProjectId, BackfillProtectedBranchMergeAccessLevelsProtectedBranchNamespaceId, BackfillProtectedBranchMergeAccessLevelsProtectedBranchProjectId, BackfillProtectedEnvironmentApprovalRulesProtectedEnvironmentGroupId, BackfillProtectedEnvironmentApprovalRulesProtectedEnvironmentProjectId, BackfillProtectedEnvironmentDeployAccessLevelsProtectedEnvironmentGroupId, BackfillProtectedEnvironmentDeployAccessLevelsProtectedEnvironmentProjectId, BackfillProtectedTagCreateAccessLevelsProjectId, BackfillRelatedEpicLinksGroupId, BackfillReleaseLinksProjectId, BackfillRemoteDevelopmentAgentConfigsProjectId, BackfillResourceLinkEventsNamespaceId, BackfillResourceWeightEventsNamespaceId, BackfillSbomOccurrencesVulnerabilitiesProjectId, BackfillSecurityFindingsProjectId, BackfillSecurityOrchestrationPolicyRuleSchedulesNamespaceId, BackfillSecurityOrchestrationPolicyRuleSchedulesProjectId, BackfillSentryIssuesNamespaceId, BackfillStatusCheckResponsesProjectId, BackfillStatusPagePublishedIncidentsNamespaceId, BackfillSubscriptionUserAddOnAssignmentsOrganizationId, BackfillTerraformStateVersionsProjectId, BackfillUserAchievementsNamespaceId, BackfillVulnerabilityExternalIssueLinksProjectId, BackfillVulnerabilityFindingEvidencesProjectId, BackfillVulnerabilityFindingLinksProjectId, BackfillVulnerabilityFindingSignaturesProjectId, BackfillVulnerabilityFindingsRemediationsProjectId, BackfillVulnerabilityFlagsProjectId, BackfillVulnerabilityIssueLinksProjectId, BackfillVulnerabilityMergeRequestLinksProjectId, BackfillVulnerabilityOccurrenceIdentifiersProjectId, BackfillVulnerabilityStateTransitionsProjectId, BackfillVulnerabilityUserMentionsProjectId, BackfillWikiPageSlugsProjectId, BackfillWikiRepositoryStatesProjectId, BackfillWorkItemParentLinksNamespaceId, BackfillWorkItemProgressesNamespaceId, BackfillWorkspaceVariablesProjectId

Constant Summary

Constants inherited from BatchedMigrationJob

Gitlab::BackgroundMigration::BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, cursor, cursor?, cursor_columns, feature_category, #filter_batch, generic_instance, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Constructor Details

This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob

Instance Method Details

#backfill_via_table_primary_keyObject



15
16
17
# File 'lib/gitlab/background_migration/backfill_desired_sharding_key_job.rb', line 15

def backfill_via_table_primary_key
  'id'
end

#construct_query(sub_batch:) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/background_migration/backfill_desired_sharding_key_job.rb', line 19

def construct_query(sub_batch:)
  <<~SQL
    UPDATE #{batch_table}
    SET #{backfill_column} = #{backfill_via_table}.#{backfill_via_column}
    FROM #{backfill_via_table}
    WHERE #{backfill_via_table}.#{backfill_via_table_primary_key} = #{batch_table}.#{backfill_via_foreign_key}
    AND #{batch_table}.#{batch_column} IN (#{sub_batch.select(batch_column).to_sql})
  SQL
end

#performObject



9
10
11
12
13
# File 'lib/gitlab/background_migration/backfill_desired_sharding_key_job.rb', line 9

def perform
  each_sub_batch do |sub_batch|
    sub_batch.connection.execute(construct_query(sub_batch: sub_batch.where(backfill_column => nil)))
  end
end