Low commit activity in last 3 years
There's a lot of open issues
A long-lived project that still receives updates
Run your data migration tasks in a db:migrate-like manner
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
>= 12.3.3
= 3.5.0

Runtime

>= 4.0.0
 Project Readme

Rails Data Migrations

Build Rubocop Gem Version

Why?

Have you ever run into a problem when alongside with DB schema migrations (managed by rake db:migrate in Rails) you have to often change your DB content, as well? If you read this, you probably tried to use schema migrations do change your data after schema changes, but this is not a recommended way and sometimes data changes could take a long time, so they will block your app at the deploy time. Another approach is to use rake tasks to run your changes after db:migrate or even independently. But this could also become a mess after some time if you have multiple developers in your project, and you need to change your data often.

This is our solution we came up with in our company - run data migration tasks in a db:migrate-like manner

Usage

To create a data migration you need to run:

rails generate data_migration migration_name

and this will create a migration_name.rb file in db/data_migrations folder with a following content:

class MigrationName < DataMigration
  def up
    # put your code here
  end
end

so all we need to do is to put some ruby code inside the up method.

Finally, at the release time, you need to run

rake data:migrate

This will run all pending data migrations and store migration history in data_migrations table. You're all set.

Rails Support

Rails 4.0 and higher

Installation

Add this line to your application's Gemfile:

gem 'rails-data-migrations'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-data-migrations

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Run tests (appraisal install && appraisal rake)
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

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