4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/generators/angry_batch/templates/add_metadata_and_counters_to_angry_batch_tables.rb', line 4
def up
change_table :angry_batch_batches do |t|
begin
t.jsonb :metadata, null: false, default: {}
rescue NoMethodError
t.json :metadata, null: false, default: {}
end
t.integer :completed_jobs_count, null: false, default: 0
t.integer :failed_jobs_count, null: false, default: 0
end
change_column_default :angry_batch_batches, :state, from: 'scheduling', to: 'pending'
execute "UPDATE angry_batch_batches SET state = 'pending' WHERE state = 'scheduling'"
execute " UPDATE angry_batch_batches SET\n completed_jobs_count = (SELECT COUNT(*) FROM angry_batch_jobs WHERE angry_batch_jobs.batch_id = angry_batch_batches.id AND angry_batch_jobs.state = 'completed'),\n failed_jobs_count = (SELECT COUNT(*) FROM angry_batch_jobs WHERE angry_batch_jobs.batch_id = angry_batch_batches.id AND angry_batch_jobs.state = 'failed')\n SQL\nend\n".squish
|