X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4403160024a6de9d2bba41cf5377aa5c3d462500..0eb72b526bf8bbb011551ecf019f604e17a534f1:/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..77310d3ac9 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 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class AddStateToJob < ActiveRecord::Migration + include CurrentApiClient + def up - if !column_exists?(:jobs, :state) + ActiveRecord::Base.transaction do add_column :jobs, :state, :string - end - - Job.reset_column_information - - act_as_system_user do - Job.all.each do |job| - # before_save filter will set state based on job status - job.save! - end + 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