The project is in a healthy, maintained state
Migrate handler of text column to json column for delayed_job
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

DelayedJobJson

Migrate handler of text column to json column for delayed_job.

Dependencies

  • ruby 2.7+
  • activerecord 6.0+
  • delayed_job 4.1
  • delayed_job_active_record 4.1

Installation

Add this line to your application's Gemfile:

gem 'delayed_job_json'

And then execute:

$ bundle

Usage

Generate migration files:

$ rails generate delayed_job_json:migration

Edit generated files and leave codes only for your database. An example of generated file is shown as follows:

class AddPayloadToDelayedJobs < ActiveRecord::Migration[7.0]
  def up
    case ENV['DATABASE']
    when 'postgresql'
      add_column :delayed_jobs, :payload, :jsonb, null: false, default: {}
      add_index :delayed_jobs, :payload, using: :gin
    when 'mysql'
      add_column :delayed_jobs, :payload, :json
    else
      add_column :delayed_jobs, :payload, :json, null: false, default: {}
    end
  end

  def down
    case ENV['DATABASE']
    when 'postgresql'
      remove_column :delayed_jobs, :payload, :jsonb, null: false, default: {}
    when 'mysql'
      remove_column :delayed_jobs, :payload, :json
    else
      remove_column :delayed_jobs, :payload, :json, null: false, default: {}
    end
  end
end

Then run migration:

$ rake db:migrate

This migration adds payload column to delayed_jobs table, and YAML data in handler column is migrated to payload as json data.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kanety/delayed_job_json.

License

The gem is available as open source under the terms of the MIT License.