Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20140918153705_add_state_to_job.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class AddStateToJob < ActiveRecord::Migration
6   include CurrentApiClient
7
8   def up
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'])
19     end
20   end
21
22   def down
23     remove_column :jobs, :state
24   end
25 end