{"id":13747277,"url":"https://github.com/ilyakatz/data-migrate","last_synced_at":"2025-05-14T10:06:40.445Z","repository":{"id":38896428,"uuid":"1633771","full_name":"ilyakatz/data-migrate","owner":"ilyakatz","description":"Migrate and update data alongside your database structure.","archived":false,"fork":false,"pushed_at":"2025-04-17T22:32:29.000Z","size":669,"stargazers_count":1464,"open_issues_count":34,"forks_count":195,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-05-14T07:07:52.046Z","etag":null,"topics":["data-schema","rails","schema-migrations"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ilyakatz.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-04-19T02:47:06.000Z","updated_at":"2025-05-12T20:30:25.000Z","dependencies_parsed_at":"2023-12-09T04:25:37.710Z","dependency_job_id":"25eddc7d-d7ac-4861-8d01-c9cec9b18946","html_url":"https://github.com/ilyakatz/data-migrate","commit_stats":{"total_commits":377,"total_committers":65,"mean_commits":5.8,"dds":0.6710875331564987,"last_synced_commit":"68bab895d3054484e8fd09dad2334eb47eba999d"},"previous_names":["ajvargo/data-migrate"],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyakatz%2Fdata-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyakatz%2Fdata-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyakatz%2Fdata-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyakatz%2Fdata-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilyakatz","download_url":"https://codeload.github.com/ilyakatz/data-migrate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254119473,"owners_count":22017951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-schema","rails","schema-migrations"],"created_at":"2024-08-03T06:01:23.646Z","updated_at":"2025-05-14T10:06:40.318Z","avatar_url":"https://github.com/ilyakatz.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Data Migrate\n\n- [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)\n- [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)\n- ![.github/workflows/build.yml](https://github.com/ilyakatz/data-migrate/actions/workflows/.github/workflows/build.yml/badge.svg)\n- [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)\n\nRun data migrations alongside schema migrations.\n\nData migrations are stored in `db/data`. They act like schema\nmigrations, except they should be reserved for data migrations. For\ninstance, if you realize you need to titleize all your titles, this\nis the place to do it.\n\n![directory tree example](./screenshot.png)\n\n## Why should I use this?\n\nWith data-migrate you can generate your migrations for data as you would schema\nin your regular work flow.\n\nFor setting tasks that don't require any intermediate AR activity, like\ndev and test, you stick with `db:migrate`. For production and QA, you\nchange their scripts to `db:migrate:with_data`. Of course you want to\ntest your migration, so you have the choice of `db:migrate:with_data` or\n`data:migrate` to just capture that data change.\n\n## What does it do?\n\nData migrations are stored in `db/data`. They act like schema\nmigrations, except they should be reserved for data migrations. For\ninstance, if you realize you need to titleize all yours titles, this\nis the place to do it. Running any of the provided rake tasks also\ncreates a data schema table to mirror the usual schema migrations\ntable to track all migrations.\n\n## Rails Support\n\nSupport Rails 6.1 through 8.0\n\nFor **Rails 6.0** support, please use gem version `9.1.x`:\n\n```ruby\ngem 'data_migrate', '~\u003e 9.1.0'\n```\n\n#### v1\n\nIf you've installed previous to v1.1.0, you'll want to delete the\n`create_data_migrations_table` migration.\n\n## Installation\n\nAdd the gem to your project\n\n    # Gemfile\n    gem 'data_migrate'\n\nThen `bundle install` and you are ready to go.\n\nSo you know, when you use one of the provide rake tasks, a table\ncalled `data_migrations` will be created in your database. This\nis to mirror the way the standard `db` rake tasks work.\n\n## Usage\n\n### Generating Migrations\n\nYou can generate a data migration as you would a schema migration:\n\n    rails g data_migration add_this_to_that\n\n### Rake Tasks\n\n    $\u003e rake -T data\n    rake data:abort_if_pending_migrations          # Raises an error if there are pending data migrations\n    rake data:dump                                 # Create a db/data_schema.rb file that stores the current data version\n    rake data:forward                              # Pushes the schema to the next version (specify steps w/ STEP=n)\n    rake data:migrate                              # Migrate data migrations (options: VERSION=x, VERBOSE=false)\n    rake data:migrate:down                         # Runs the \"down\" for a given migration VERSION\n    rake data:migrate:redo                         # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)\n    rake data:migrate:status                       # Display status of data migrations\n    rake data:migrate:up                           # Runs the \"up\" for a given migration VERSION\n    rake data:rollback                             # Rolls the schema back to the previous version (specify steps w/ STEP=n)\n    rake data:schema:load                          # Load data_schema.rb file into the database without running the data migrations\n    rake data:version                              # Retrieves the current schema version number for data migrations\n    rake db:abort_if_pending_migrations:with_data  # Raises an error if there are pending migrations or data migrations\n    rake db:forward:with_data                      # Pushes the schema to the next version (specify steps w/ STEP=n)\n    rake db:migrate:down:with_data                 # Runs the \"down\" for a given migration VERSION\n    rake db:migrate:redo:with_data                 # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)\n    rake db:migrate:status:with_data               # Display status of data and schema migrations\n    rake db:migrate:up:with_data                   # Runs the \"up\" for a given migration VERSION\n    rake db:migrate:with_data                      # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)\n    rake db:prepare:with_data                      # Runs setup if database does not exist, or runs data and schema migrations if it does\n    rake db:rollback:with_data                     # Rolls the schema back to the previous version (specify steps w/ STEP=n)\n    rake db:schema:load:with_data                  # Load both schema.rb and data_schema.rb file into the database\n    rake db:structure:load:with_data               # Load both structure.sql and data_schema.rb file into the database\n    rake db:version:with_data                      # Retrieves the current schema version numbers for data and schema migrations\n\n\nTasks 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.\n\nWith '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.\n\nWhen using `rake db:migrate:with_data` migrations will be run in ascending order by their version. For example, if you have a data migration with version 20230410000000 and a schema migration with version 20230415000000, expect the data migration to run first.\n\n`rake db:migrate:status:with_data` provides an additional column to indicate which type of migration.\n\n### Configuration\n\n`data_migrate` respects `ActiveRecord::Base.dump_schema_after_migration`. If it is set to `false`, data schema file will not be generated\n\nBy default, data migrations are added to the `db/data/` path.\nYou can override this setting in `config/initializers/data_migrate.rb`\n\n```ruby\nDataMigrate.configure do |config|\n  config.data_migrations_table_name = 'my_migrations_database_name'\n  config.data_migrations_path = 'db/awesomepath/'\n  config.data_template_path = Rails.root.join(\"lib\", \"awesomepath\", \"custom_data_migration.rb\")\n  config.db_configuration = {\n    'host' =\u003e '127.0.0.1',\n    'database' =\u003e 'awesome_database',\n    'adapter' =\u003e 'mysql2',\n    'username' =\u003e 'root',\n    'password' =\u003e nil,\n  }\n  config.spec_name = 'primary'\nend\n\n```\n\n## Capistrano Support\n\nThe gem comes with a capistrano task that can be used instead of `capistrano/rails/migrations`.\n\nJust add this line to your Capfile:\n\n```ruby\nrequire 'capistrano/data_migrate'\n```\n\nFrom now on capistrano will run `rake db:migrate:with_data` in every deploy.\n\n## Rails Engines support\n\nThis gem also has a initial support for adding data migrations inside Rails engines.\nJust add your engines directory pattern to data_migrations initializer, for example\nin the case your engines are located in `engines` folder you can set it up like this:\n\n```ruby\nDataMigrate.configure do |config|\n  config.data_migrations_path = ['db/data'] + Dir['engines/**/db/data']\nend\n```\n\nThen, in the Engine's `db/data` folder, you can add data migrations and run them as usual.\n\n### Contributing\n\n## Testing\n\nRun tests for a specific version of Rails\n\n```\nbundle exec appraisal rails-6.1 rspec\nbundle exec appraisal rails-7.0 rspec\nbundle exec appraisal rails-7.1 rspec\nbundle exec appraisal rails-7.2 rspec\nbundle exec appraisal rails-8.0 rspec\n```\n\n## Releasing new version\n\n1. Update version.rb file, run `bundle exec appraisal` to update the version in corresponding gemfile.lock\n2. Create a new tag, eg `git tag 9.4.1`\n3. Go to https://github.com/ilyakatz/data-migrate/tags\n4. Click \"Create release\" under 9.4.1\n5. CLick \"Generate release notes\"\n6. Click \"Publish release\"\n\n## Thanks\n\n[Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!\n\n[Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea and providing guidance.\n\nYou! Yes, you. Thanks for checking it out.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyakatz%2Fdata-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filyakatz%2Fdata-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyakatz%2Fdata-migrate/lists"}