Merge branch 'master' into 3177-collection-choose-files
[arvados.git] / services / api / db / migrate / 20140918153705_add_state_to_job.rb
1 class AddStateToJob < ActiveRecord::Migration
2   include CurrentApiClient
3
4   def up
5     ActiveRecord::Base.transaction do
6       add_column :jobs, :state, :string
7       Job.reset_column_information
8       Job.update_all({state: 'Cancelled'}, ['state is null and cancelled_at is not null'])
9       Job.update_all({state: 'Failed'}, ['state is null and success = ?', false])
10       Job.update_all({state: 'Complete'}, ['state is null and success = ?', true])
11       Job.update_all({state: 'Running'}, ['state is null and running = ?', true])
12       # Locked/started, but not Running/Failed/Complete? Let's assume it failed.
13       Job.update_all({state: 'Failed'}, ['state is null and (is_locked_by_uuid is not null or started_at is not null)'])
14       Job.update_all({state: 'Queued'}, ['state is null'])
15     end
16   end
17
18   def down
19     remove_column :jobs, :state
20   end
21 end