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
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-30 15:22:23 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-30 15:22:23 +0300
commit9c7c95c768cd5294dd085c2fc2425fae91c4c689 (patch)
treef05de41bee3d35f451bfe0ef22fd2cc929d7ce1a /db/post_migrate
parent81dba76b9d7d120cd22e3619a4058bd4885be9bc (diff)
Add initial changes for stages statuses migration
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20170630111158_migrate_stages_statuses.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/db/post_migrate/20170630111158_migrate_stages_statuses.rb b/db/post_migrate/20170630111158_migrate_stages_statuses.rb
new file mode 100644
index 00000000000..b4b76893595
--- /dev/null
+++ b/db/post_migrate/20170630111158_migrate_stages_statuses.rb
@@ -0,0 +1,76 @@
+class MigrateStagesStatuses < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ class Build < ActiveRecord::Base
+ self.table_name = 'ci_builds'
+
+ scope :relevant, -> do
+ where(status: %w[pending running success failed canceled skipped manual])
+ end
+
+ scope :created, -> { where(status: 'created') }
+ scope :running, -> { where(status: 'running') }
+ scope :pending, -> { where(status: 'pending') }
+ scope :success, -> { where(status: 'success') }
+ scope :failed, -> { where(status: 'failed') }
+ scope :canceled, -> { where(status: 'canceled') }
+ scope :skipped, -> { where(status: 'skipped') }
+ scope :manual, -> { where(status: 'manual') }
+
+ scope :failed_but_allowed, -> do
+ where(allow_failure: true, status: [:failed, :canceled])
+ end
+
+ scope :exclude_ignored, -> do
+ where("allow_failure = ? OR status IN (?)",
+ false, all_state_names - [:failed, :canceled, :manual])
+ end
+
+ def status_sql
+ scope_relevant = relevant.exclude_ignored
+ scope_warnings = relevant.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
+
+ "(CASE
+ WHEN (#{builds})=(#{skipped}) AND (#{warnings}) THEN 'success'
+ WHEN (#{builds})=(#{skipped}) THEN 'skipped'
+ WHEN (#{builds})=(#{success}) THEN 'success'
+ WHEN (#{builds})=(#{created}) THEN 'created'
+ WHEN (#{builds})=(#{success})+(#{skipped}) THEN 'success'
+ WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled'
+ WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending'
+ WHEN (#{running})+(#{pending})>0 THEN 'running'
+ WHEN (#{manual})>0 THEN 'manual'
+ WHEN (#{created})>0 THEN 'running'
+ ELSE 'failed'
+ END)"
+ end
+ end
+
+ def up
+ execute <<-SQL.strip_heredoc
+ SQL
+ end
+
+ def down
+ execute <<-SQL.strip_heredoc
+ UPDATE ci_stages SET status = null
+ SQL
+ end
+
+ private
+
+end