summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-04 13:43:26 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-04 13:43:26 +0200
commitd60ce6e9f44eba769a6ad595014ae96095169dd2 (patch)
tree0156fbd625e675332d09f81d6110cbcd2ea3f442 /db
parent7103c4a707157594c261ba2f68fbb649ca4df769 (diff)
downloadgitlab-ce-d60ce6e9f44eba769a6ad595014ae96095169dd2.tar.gz
Implement initial working stages statuses migration
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20170630111158_migrate_stages_statuses.rb46
1 files changed, 20 insertions, 26 deletions
diff --git a/db/post_migrate/20170630111158_migrate_stages_statuses.rb b/db/post_migrate/20170630111158_migrate_stages_statuses.rb
index 8c6de84adf5..62542ed0001 100644
--- a/db/post_migrate/20170630111158_migrate_stages_statuses.rb
+++ b/db/post_migrate/20170630111158_migrate_stages_statuses.rb
@@ -48,34 +48,31 @@ class MigrateStagesStatuses < ActiveRecord::Migration
canceled = scope_relevant.canceled.select('count(*)').to_sql
warnings = scope_warnings.select('count(*) > 0').to_sql
- "(CASE
- WHEN (#{builds})=(#{skipped}) AND (#{warnings}) THEN #{STATUSES[:success]}
- WHEN (#{builds})=(#{skipped}) THEN #{STATUSES[:skipped]}
- WHEN (#{builds})=(#{success}) THEN #{STATUSES[:success]}
- WHEN (#{builds})=(#{created}) THEN #{STATUSES[:created]}
- WHEN (#{builds})=(#{success})+(#{skipped}) THEN #{STATUSES[:success]}
- WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN #{STATUSES[:canceled]}
- WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN #{STATUSES[:pending]}
- WHEN (#{running})+(#{pending})>0 THEN '#{STATUSES[:running]}
- WHEN (#{manual})>0 THEN #{STATUSES[:manual]}
- WHEN (#{created})>0 THEN #{STATUSES[:running]}
- ELSE #{STATUSES[:failed]}
- END)"
+ <<-SQL.strip_heredoc
+ (CASE
+ WHEN (#{builds}) = (#{skipped}) AND (#{warnings}) THEN #{STATUSES[:success]}
+ WHEN (#{builds}) = (#{skipped}) THEN #{STATUSES[:skipped]}
+ WHEN (#{builds}) = (#{success}) THEN #{STATUSES[:success]}
+ WHEN (#{builds}) = (#{created}) THEN #{STATUSES[:created]}
+ WHEN (#{builds}) = (#{success}) + (#{skipped}) THEN #{STATUSES[:success]}
+ WHEN (#{builds}) = (#{success}) + (#{skipped}) + (#{canceled}) THEN #{STATUSES[:canceled]}
+ WHEN (#{builds}) = (#{created}) + (#{skipped}) + (#{pending}) THEN #{STATUSES[:pending]}
+ WHEN (#{running}) + (#{pending}) > 0 THEN #{STATUSES[:running]}
+ WHEN (#{manual}) > 0 THEN #{STATUSES[:manual]}
+ WHEN (#{created}) > 0 THEN #{STATUSES[:running]}
+ ELSE #{STATUSES[:failed]}
+ END)
+ SQL
end
end
def up
- Stage.all.in_batches(of: 10000) do |relation|
- status_sql = Build
- .where('ci_builds.commit_id = ci_stages.pipeline_id')
- .where('ci_builds.stage = ci_stages.name')
- .status_sql
+ status_sql = Build
+ .where('ci_builds.commit_id = ci_stages.pipeline_id')
+ .where('ci_builds.stage = ci_stages.name')
+ .status_sql
- execute <<-SQL.strip_heredoc
- UPDATE ci_stages SET status = #{status_sql}
- WHERE id = (#{relation.select(:id).to_sql})
- SQL
- end
+ update_column_in_batches(:ci_stages, :status, Arel.sql("(#{status_sql})"))
end
def down
@@ -83,7 +80,4 @@ class MigrateStagesStatuses < ActiveRecord::Migration
UPDATE ci_stages SET status = null
SQL
end
-
- private
-
end