1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class AddStateToJob < ActiveRecord::Migration
6 include CurrentApiClient
9 ActiveRecord::Base.transaction do
10 add_column :jobs, :state, :string
11 Job.reset_column_information
12 Job.update_all({state: 'Cancelled'}, ['state is null and cancelled_at is not null'])
13 Job.update_all({state: 'Failed'}, ['state is null and success = ?', false])
14 Job.update_all({state: 'Complete'}, ['state is null and success = ?', true])
15 Job.update_all({state: 'Running'}, ['state is null and running = ?', true])
16 # Locked/started, but not Running/Failed/Complete? Let's assume it failed.
17 Job.update_all({state: 'Failed'}, ['state is null and (is_locked_by_uuid is not null or started_at is not null)'])
18 Job.update_all({state: 'Queued'}, ['state is null'])
23 remove_column :jobs, :state