Sha256: 4b85cb6b631b05ab91cff90c068866d7b12acd7c1954097e8222662382b98ad3

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

class CreateDelayedJobGroups < ActiveRecord::Migration[<%= ActiveRecord::VERSION::MAJOR %>.<%= ActiveRecord::VERSION::MINOR %>]

  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 :failure_cancels_group, default: true, null: false
      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

10 entries across 10 versions & 1 rubygems

Version Path
delayed_job_groups_plugin-0.12.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.11.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.10.1 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.10.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.9.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.8.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.7.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.6.2 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.6.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb
delayed_job_groups_plugin-0.5.0 lib/generators/delayed_job_groups_plugin/templates/migration.erb