1 class AddStateToJob < ActiveRecord::Migration
2 include CurrentApiClient
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'])
19 remove_column :jobs, :state