0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Running tasks for Rails as migration
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Tasks Migration

Getting started

Tasks Migration works with Rails 4.1 onwards. Add the following line to your Gemfile

gem "tasks-migration"

Then run

bundle install

Next, you need to run the generator:

rails generate tasks_migration:install

This command will create 2 files:

  • db/migrate/<timestamp>_create_tasks_migration_schema.rb (Create new table tasks_migration_schema in database)
  • config/tasks_migration.yml (Define Tasks will be runs )

Usage

Basic

Create a new task by command:

rails generate tasks_migration:task <TaskName> [--no-suffix]

Business Logic will be handled in method self.excute on file app/migration_tasks/<task_name>.rb. Example:

# app/migration_tasks/hello_world_task.rb
class HelloWorldTask
  def self.execute
      puts "Hello world :D"
  end
end

And add this task into config/tasks_migration.yml. Example:

# config/tasks_migration.yml
tasks:
  - HelloWorldTask

The last, you run command:

bundle exec rake tasks_migration:migrate

Capistrano

Using Tasks Migration with Capistrano (after deploying completed deploy:finished) we just need to add following line into Capfile:

require "capistrano3/tasks-migration"

Another way, you also can do it manually through Capistrano Task:

bundle exec cap <stage> tasks_migration:migrate

Credits

Special thanks to ThanhTT for this file (README.md)