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
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-02-05 18:22:19 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-02-05 18:22:19 +0300
commitb5c69ce3abed5f8269dee256fca02d3e74b30347 (patch)
tree596f9f41ef145c08c668271e1c5c639b20767360 /db
parent5f57c7a5a54d844fb3f8566dd81da3cdde2f3c5b (diff)
Retry migration removing stages in case of duplicates
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
index be5a80261c0..9644cfabb60 100644
--- a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
+++ b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
@@ -3,12 +3,15 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
DOWNTIME = false
- def up
- remove_concurrent_index :ci_stages, [:pipeline_id, :name]
+ disable_ddl_transaction!
+ def up(attempts: 100)
+ remove_outdated_index!
remove_redundant_pipeline_stages!
-
- add_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true
+ add_unique_index!
+ rescue ActiveRecord::RecordNotUnique
+ retry if (attempts -= 1) > 0
+ raise
end
def down
@@ -18,6 +21,16 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
private
+ def remove_outdated_index!
+ return unless index_exists?(:ci_stages, [:pipeline_id, :name])
+
+ remove_concurrent_index :ci_stages, [:pipeline_id, :name]
+ end
+
+ def add_unique_index!
+ add_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true
+ end
+
def remove_redundant_pipeline_stages!
redundant_stages_ids = <<~SQL
SELECT id FROM ci_stages WHERE (pipeline_id, name) IN (