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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb')
-rw-r--r--db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
new file mode 100644
index 00000000000..3868e0adae1
--- /dev/null
+++ b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
@@ -0,0 +1,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