X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2bc8ce335b15136ce39b2652ab41e20b15632d08..5acd68562b23c0293140a9de6443855b6612266b:/services/api/db/migrate/20140918153705_add_state_to_job.rb diff --git a/services/api/db/migrate/20140918153705_add_state_to_job.rb b/services/api/db/migrate/20140918153705_add_state_to_job.rb index 810c3a70ce..46a5e84362 100644 --- a/services/api/db/migrate/20140918153705_add_state_to_job.rb +++ b/services/api/db/migrate/20140918153705_add_state_to_job.rb @@ -1,22 +1,25 @@ -class AddStateToJob < ActiveRecord::Migration - def up - if !column_exists?(:jobs, :state) - add_column :jobs, :state, :string - end +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 - Job.reset_column_information +class AddStateToJob < ActiveRecord::Migration[4.2] + include CurrentApiClient - act_as_system_user do - Job.all.each do |job| - # before_save filter will set state based on job status - job.save! - end + def up + ActiveRecord::Base.transaction do + add_column :jobs, :state, :string + Job.reset_column_information + Job.update_all({state: 'Cancelled'}, ['state is null and cancelled_at is not null']) + Job.update_all({state: 'Failed'}, ['state is null and success = ?', false]) + Job.update_all({state: 'Complete'}, ['state is null and success = ?', true]) + Job.update_all({state: 'Running'}, ['state is null and running = ?', true]) + # Locked/started, but not Running/Failed/Complete? Let's assume it failed. + Job.update_all({state: 'Failed'}, ['state is null and (is_locked_by_uuid is not null or started_at is not null)']) + Job.update_all({state: 'Queued'}, ['state is null']) end end def down - if column_exists?(:jobs, :state) - remove_column :jobs, :state - end + remove_column :jobs, :state end end