Class: CreateAngryBatchTables

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/angry_batch/templates/create_angry_batch_tables.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/angry_batch/templates/create_angry_batch_tables.rb', line 4

def change
  create_table :angry_batch_batches do |t|
    begin
      t.jsonb :complete_handlers, null: false, default: []
      t.jsonb :failure_handlers, null: false, default: []
    rescue NoMethodError
      t.json :complete_handlers, null: false, default: []
      t.json :failure_handlers, null: false, default: []
    end

    t.datetime :finished_at
    t.integer  :jobs_count, null: false, default: 0
    t.string   :label
    t.string   :state, null: false, default: 'scheduling'

    t.timestamps
  end

  add_index :angry_batch_batches, :state

  create_table :angry_batch_jobs do |t|
    t.references :batch, null: false, foreign_key: { to_table: :angry_batch_batches }, index: false
    t.string     :active_job_class, null: false
    t.string     :active_job_idx, null: false

    begin
      t.jsonb :active_job_arguments
    rescue NoMethodError
      t.json :active_job_arguments
    end

    t.string     :error_message
    t.string     :state, null: false, default: 'pending'

    t.timestamps
  end

  add_index :angry_batch_jobs, :active_job_idx, unique: true
  add_index :angry_batch_jobs, %i(batch_id state)
end