Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_orphaned_deployments.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ac4111ff0f18930a09906f527445737633dca82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Background migration for deleting orphaned deployments.
    class DeleteOrphanedDeployments
      include Database::MigrationHelpers

      def perform(start_id, end_id)
        orphaned_deployments
          .where(id: start_id..end_id)
          .delete_all

        mark_job_as_succeeded(start_id, end_id)
      end

      def orphaned_deployments
        define_batchable_model('deployments')
          .where('NOT EXISTS (SELECT 1 FROM environments WHERE deployments.environment_id = environments.id)')
      end

      private

      def mark_job_as_succeeded(*arguments)
        Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded(
          self.class.name.demodulize,
          arguments
        )
      end
    end
  end
end