X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3cc699f70a514878b7ce7adbc3c96e73f92fdf82..415910149bed2eef6ae818b7c059d413934df06e:/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