All Projects → ilyakatz → Data Migrate

ilyakatz / Data Migrate

Licence: mit
Migrate and update data alongside your database structure.

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Data Migrate

Action policy
Authorization framework for Ruby/Rails applications
Stars: ✭ 718 (-12.55%)
Mutual labels:  rails
Pay
Payments for Ruby on Rails apps
Stars: ✭ 759 (-7.55%)
Mutual labels:  rails
Graphiti
Stylish Graph APIs
Stars: ✭ 783 (-4.63%)
Mutual labels:  rails
Paper trail
Track changes to your rails models
Stars: ✭ 6,185 (+653.35%)
Mutual labels:  rails
Activerecord Postgis Adapter
ActiveRecord connection adapter for PostGIS, based on postgresql and rgeo
Stars: ✭ 746 (-9.14%)
Mutual labels:  rails
Rails
Official Ruby on Rails specific tasks for Capistrano
Stars: ✭ 773 (-5.85%)
Mutual labels:  rails
Railsgoat
A vulnerable version of Rails that follows the OWASP Top 10
Stars: ✭ 699 (-14.86%)
Mutual labels:  rails
Rails Settings
Manage settings with Ruby on Rails
Stars: ✭ 807 (-1.71%)
Mutual labels:  rails
Buffalo
Rapid Web Development w/ Go
Stars: ✭ 6,476 (+688.79%)
Mutual labels:  rails
Materialize Sass
Materializecss rubygem for Rails Asset Pipeline / Sprockets
Stars: ✭ 785 (-4.38%)
Mutual labels:  rails
Brakeman
A static analysis security vulnerability scanner for Ruby on Rails applications
Stars: ✭ 6,281 (+665.04%)
Mutual labels:  rails
Rails Handbook
Describing the development process used by the Infinum Rails Team.
Stars: ✭ 738 (-10.11%)
Mutual labels:  rails
React Rails
Integrate React.js with Rails views and controllers, the asset pipeline, or webpacker.
Stars: ✭ 6,417 (+681.61%)
Mutual labels:  rails
Access Granted
Multi-role and whitelist based authorization gem for Rails (and not only Rails!)
Stars: ✭ 733 (-10.72%)
Mutual labels:  rails
Active link to
Rails view helper to manage "active" state of a link
Stars: ✭ 792 (-3.53%)
Mutual labels:  rails
Redis Search
Deprecated! High performance real-time prefix search, indexes store in Redis for Rails application
Stars: ✭ 713 (-13.15%)
Mutual labels:  rails
Rails Template
Application template for Rails 6 projects; preloaded with best practices for TDD, security, deployment, and developer productivity.
Stars: ✭ 763 (-7.06%)
Mutual labels:  rails
Ruby Articles
一些和Ruby相关的技术文章,完全原创
Stars: ✭ 5 (-99.39%)
Mutual labels:  rails
Medusa
🐈Medusa是一个红队武器库平台,目前包括扫描功能(200+个漏洞)、XSS平台、协同平台、CVE监控等功能,持续开发中 http://medusa.ascotbe.com
Stars: ✭ 796 (-3.05%)
Mutual labels:  rails
Openfarm
A free and open database for farming and gardening knowledge. You can grow anything!
Stars: ✭ 779 (-5.12%)
Mutual labels:  rails

Data Migrate

  • Version
  • License
  • Travis
  • Reviewed by Hound

Run data migrations alongside schema migrations.

Data migrations are stored in db/data. They act like schema migrations, except they should be reserved for data migrations. For instance, if you realize you need to titleize all your titles, this is the place to do it.

Travis

Why should I use this?

With data-migrate you can generate your migrations for data as you would schema in your regular work flow.

For setting tasks that don't require any intermediate AR activity, like dev and test, you stick with db:migrate. For production and QA, you change their scripts to db:migrate:with_data. Of course you want to test your migration, so you have the choice of db:migrate:with_data or data:migrate to just capture that data change.

What does it do?

Data migrations are stored in db/data. They act like schema migrations, except they should be reserved for data migrations. For instance, if you realize you need to titleize all yours titles, this is the place to do it. Running any of the provided rake tasks also creates a data schema table to mirror the usual schema migrations table to track all migrations.

Rails Support

Support Rails 5.0 through 6.0

Important notes for older versions

v2

If you upgraded to Rails 4 while using data_migrate prior to version 2, the gem wrote data migration versions into schema_migrations table. After the fix, it was corrected to write into data_migrations.

If you need to use these old migrations, add the following configuration

It is recommended to move all legacy migrations from schema_migrations table into data_migrations table

This may cause some unintended consequences. See #22

v1

If you've installed previous to v1.1.0, you'll want to delete the create_data_migrations_table migration.

Installation

Add the gem to your project

# Gemfile
gem 'data_migrate'

Then bundle install and you are ready to go.

So you know, when you use one of the provide rake tasks, a table called data_migrations will be created in your database. This is to mirror the way the standard db rake tasks work.

Usage

Generating Migrations

You can generate a data migration as you would a schema migration:

rails g data_migration add_this_to_that

Rake Tasks

$> rake -T data
rake data:abort_if_pending_migrations          # Raises an error if there are pending data migrations
rake data:dump                                 # Create a db/data_schema.rb file that stores the current data version
rake data:forward                              # Pushes the schema to the next version (specify steps w/ STEP=n)
rake data:migrate                              # Migrate data migrations (options: VERSION=x, VERBOSE=false)
rake data:migrate:down                         # Runs the "down" for a given migration VERSION
rake data:migrate:redo                         # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
rake data:migrate:status                       # Display status of data migrations
rake data:migrate:up                           # Runs the "up" for a given migration VERSION
rake data:rollback                             # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake data:schema:load                          # Load data_schema.rb file into the database without running the data migrations
rake data:version                              # Retrieves the current schema version number for data migrations
rake db:abort_if_pending_migrations:with_data  # Raises an error if there are pending migrations or data migrations
rake db:forward:with_data                      # Pushes the schema to the next version (specify steps w/ STEP=n)
rake db:migrate:down:with_data                 # Runs the "down" for a given migration VERSION
rake db:migrate:redo:with_data                 # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
rake db:migrate:status:with_data               # Display status of data and schema migrations
rake db:migrate:up:with_data                   # Runs the "up" for a given migration VERSION
rake db:migrate:with_data                      # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
rake db:rollback:with_data                     # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:load:with_data                  # Load both schema.rb and data_schema.rb file into the database
rake db:structure:load:with_data               # Load both structure.sql and data_schema.rb file into the database
rake db:version:with_data                      # Retrieves the current schema version numbers for data and schema migrations

Tasks work as they would with the 'vanilla' db version. The 'with_data' addition to the 'db' tasks will run the task in the context of both the data and schema migrations. That is, rake db:rollback:with_data will check to see if it was a schema or data migration invoked last, and do that. Tasks invoked in that space also have an additional line of output, indicating if the action is performed on data or schema.

With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.

rake db:migrate:status:with_data provides and additional column to indicate which type of migration.

Configuration

data_migrate respects ActiveRecord::Base.dump_schema_after_migration. If it is set to false, data schema file will not be generated

By default, data migrations are added to the db/data/ path. You can override this setting in config/initializers/data_migrate.rb

DataMigrate.configure do |config|
  config.data_migrations_path = 'db/awesomepath/'
  config.db_configuration = {
    'host' => '127.0.0.1',
    'database' => 'awesome_database',
    'adapter' => 'mysql2',
    'username' => 'root',
    'password' => nil,
  }
  config.spec_name = 'primary'
end

Capistrano Support

The gem comes with a capistrano task that can be used instead of capistrano/rails/migrations.

Just add this line to your Capfile:

require 'capistrano/data_migrate'

From now on capistrano will run rake db:migrate:with_data in every deploy.

Contributing

Testing

Run tests for a specific version of Rails

bundle exec appraisal install
bundle exec appraisal rails-5.1 rspec
bundle exec appraisal rails-5.2 rspec
bundle exec appraisal rails-6.0 rspec

Thanks

Andrew J Vargo Andrew was the original creator and maintainer of this project!

Jeremy Durham for fleshing out the idea and providing guidance.

You! Yes, you. Thanks for checking it out.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].