Class: Gitlab::BackgroundMigration::MigrateStageStatus::Build

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/gitlab/background_migration/migrate_stage_status.rb

Class Method Summary collapse

Class Method Details

.status_sqlObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitlab/background_migration/migrate_stage_status.rb', line 33

def self.status_sql
  scope_relevant = latest.exclude_ignored
  scope_warnings = latest.failed_but_allowed

  builds = scope_relevant.select('count(*)').to_sql
  created = scope_relevant.created.select('count(*)').to_sql
  success = scope_relevant.success.select('count(*)').to_sql
  manual = scope_relevant.manual.select('count(*)').to_sql
  pending = scope_relevant.pending.select('count(*)').to_sql
  running = scope_relevant.running.select('count(*)').to_sql
  skipped = scope_relevant.skipped.select('count(*)').to_sql
  canceled = scope_relevant.canceled.select('count(*)').to_sql
  warnings = scope_warnings.select('count(*) > 0').to_sql

  <<-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