summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-01-19 14:25:30 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-01-24 12:47:47 +0100
commit6714fbad8fc25d3cc6b295d26e3c220987c60fb0 (patch)
treecc5c7b6ce03c9d27b2a3793ad55778e13264d1d1 /db
parente2a56af930f9f7d17a6a9b638f52007a60e4cc60 (diff)
downloadgitlab-ce-6714fbad8fc25d3cc6b295d26e3c220987c60fb0.tar.gz
Remove redundant pipeline stages from the database
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb26
-rw-r--r--db/schema.rb2
2 files changed, 27 insertions, 1 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
diff --git a/db/schema.rb b/db/schema.rb
index a0901833c3d..9becd794553 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180113220114) do
+ActiveRecord::Schema.define(version: 20180119121225) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"