summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb19
-rw-r--r--db/post_migrate/20180125111139_add_unique_pipeline_stage_name_index.rb17
2 files changed, 15 insertions, 21 deletions
diff --git a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
index 89ed422ea1c..be5a80261c0 100644
--- a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
+++ b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
@@ -4,6 +4,21 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
DOWNTIME = false
def up
+ remove_concurrent_index :ci_stages, [:pipeline_id, :name]
+
+ remove_redundant_pipeline_stages!
+
+ add_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true
+ end
+
+ def down
+ remove_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true
+ add_concurrent_index :ci_stages, [:pipeline_id, :name]
+ end
+
+ private
+
+ def remove_redundant_pipeline_stages!
redundant_stages_ids = <<~SQL
SELECT id FROM ci_stages WHERE (pipeline_id, name) IN (
SELECT pipeline_id, name FROM ci_stages
@@ -27,8 +42,4 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
SQL
end
end
-
- def down
- # noop
- end
end
diff --git a/db/post_migrate/20180125111139_add_unique_pipeline_stage_name_index.rb b/db/post_migrate/20180125111139_add_unique_pipeline_stage_name_index.rb
deleted file mode 100644
index 4fa148b2446..00000000000
--- a/db/post_migrate/20180125111139_add_unique_pipeline_stage_name_index.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-class AddUniquePipelineStageNameIndex < ActiveRecord::Migration
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- remove_concurrent_index :ci_stages, [:pipeline_id, :name]
- add_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true
- end
-
- def down
- remove_concurrent_index :ci_stages, [:pipeline_id, :name], unique: true
- add_concurrent_index :ci_stages, [:pipeline_id, :name]
- end
-end