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

20180119121225_remove_redundant_pipeline_stages.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3868e0adae16188dc971b76093b6b112f7cd2714 (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
class RemoveRedundantPipelineStages < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  def up
   redundant_stages_ids = <<~SQL
      SELECT id FROM ci_stages a WHERE (
        SELECT COUNT(*) FROM ci_stages b
          WHERE a.pipeline_id = b.pipeline_id AND a.name = b.name
      ) > 1
    SQL

    execute <<~SQL
      UPDATE ci_builds SET stage_id = NULL WHERE ci_builds.stage_id IN (#{redundant_stages_ids})
    SQL

    execute <<~SQL
      DELETE FROM ci_stages WHERE ci_stages.id IN (#{redundant_stages_ids})
    SQL
  end

  def down
    # noop
  end
end