Class: AddBatchesToSolidQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/solid_queue/update/templates/db/add_batches_to_solid_queue.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



2
3
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
# File 'lib/generators/solid_queue/update/templates/db/add_batches_to_solid_queue.rb', line 2

def change
  # Fresh installs create all of this with the base schema, so skip
  # anything that already exists
  add_column :solid_queue_jobs, :batch_id, :bigint, if_not_exists: true
  add_index :solid_queue_jobs, :batch_id, if_not_exists: true

  create_table :solid_queue_batches, if_not_exists: true do |t|
    t.string :active_job_batch_id
    t.string :description
    t.text :on_finish
    t.text :on_success
    t.text :on_failure
    t.text :metadata
    t.integer :total_jobs, default: 0, null: false
    t.integer :completed_jobs, default: 0, null: false
    t.integer :failed_jobs, default: 0, null: false
    t.datetime :enqueued_at
    t.datetime :finished_at
    t.datetime :failed_at
    t.datetime :created_at, null: false
    t.datetime :updated_at, null: false

    t.index :active_job_batch_id, unique: true
    t.index :finished_at
  end

  create_table :solid_queue_batch_executions, if_not_exists: true do |t|
    t.bigint :job_id, null: false
    t.bigint :batch_id, null: false
    t.datetime :created_at, null: false

    t.index :job_id, unique: true
    t.index :batch_id
    t.foreign_key :solid_queue_batches, column: :batch_id, on_delete: :cascade
    t.foreign_key :solid_queue_jobs, column: :job_id, on_delete: :cascade
  end
end