Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anjlab/rails-data-migrations
Run your data migration scripts like a master
https://github.com/anjlab/rails-data-migrations
Last synced: 3 months ago
JSON representation
Run your data migration scripts like a master
- Host: GitHub
- URL: https://github.com/anjlab/rails-data-migrations
- Owner: anjlab
- License: mit
- Created: 2016-11-02T12:14:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-20T11:15:03.000Z (6 months ago)
- Last Synced: 2024-05-31T21:07:34.130Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 38.1 KB
- Stars: 116
- Watchers: 8
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Rails Data Migrations
[![Build](https://github.com/anjlab/rails-data-migrations/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/anjlab/rails-data-migrations/actions/workflows/test.yml)
[![Rubocop](https://github.com/anjlab/rails-data-migrations/actions/workflows/checkstyle.yml/badge.svg?branch=master)](https://github.com/anjlab/rails-data-migrations/actions/workflows/checkstyle.yml)
[![Gem Version](https://badge.fury.io/rb/rails-data-migrations.svg)](https://badge.fury.io/rb/rails-data-migrations)## 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](https://robots.thoughtbot.com/data-migrations-in-rails) 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:
```ruby
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:
```ruby
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`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).