Sha256: e78dd5f6f7ac6fc06f5f898805787d32bc62cbc05670282826fa4ac146777b6a

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# encoding: UTF-8

class CreateDelayedJobGroups < ActiveRecord::Migration

  def up
    add_column(:delayed_jobs, :blocked, :boolean, default: false, null: false)
    add_column(:delayed_jobs, :job_group_id, :integer)
    add_index(:delayed_jobs, :job_group_id)

    if partial_indexes_supported?
      remove_index(:delayed_jobs, name: :delayed_jobs_priority)
      execute <<-SQL
         CREATE INDEX delayed_jobs_priority
         ON delayed_jobs(priority, run_at)
        WHERE failed_at IS NULL AND blocked = FALSE
      SQL
    end

    create_table(:delayed_job_groups) do |t|
      t.text :on_completion_job
      t.text :on_completion_job_options
      t.text :on_cancellation_job
      t.text :on_cancellation_job_options
      t.boolean :queueing_complete, default: false, null: false
      t.boolean :blocked, default: false, null: false
    end
  end

  def down
    remove_columns(:delayed_jobs, :blocked, :job_group_id)

    if partial_indexes_supported?
      execute <<-SQL
         CREATE INDEX delayed_jobs_priority
         ON delayed_jobs(priority, run_at)
         WHERE failed_at IS NULL
      SQL
    end

    drop_table(:delayed_job_groups)
  end

  def partial_indexes_supported?
    connection.adapter_name == 'PostgreSQL'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
delayed_job_groups_plugin-0.1.1 lib/generators/delayed_job_groups_plugin/templates/migration.rb
delayed_job_groups_plugin-0.1.0 lib/generators/delayed_job_groups_plugin/templates/migration.rb