<commit_before># DataTasks

Adds a second migration phase to a Rails project for data migrations. Just
like migrations, these can be run once and only once in each environment
with a single command during every deployment.

## Installation

Add this line to your application's Gemfile:

    gem 'data_tasks'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install empty_gem

## Usage

To generate a data migration, use the rails generator:

    rails generate data_task MigrateSomeData

This will create:

    db/data_tasks/20120822023011_migrate_some_data.rb

Run all pending data tasks with rake:

    rake data:migrate

## Common Problems

If you're running your Rails processes in threadsafe mode, you'll get errors about undefined
constants when trying to access model classes. You'll need to disable while running
rake tasks. In your environment file (ex. `config/environments/production.rb`), change:

    config.threadsafe!

to:

    config.threadsafe! unless $rails_rake_task

If you don't want to make that change, you can explicitly load the required model classes
inside the migration class, or define stub model classes. For example, if you wanted to
add a new SideHatch record in the migration, you could define:

    class SideHatch < ActiveRecord::Base; end

    class CreateSideHatch < ActiveRecord::Migration<commit_msg>Added note about data:assume_migrated to README<commit_after># DataTasks

Adds a second migration phase to a Rails project for data migrations. Just
like migrations, these can be run once and only once in each environment
with a single command during every deployment.

## Installation

Add this line to your application's Gemfile:

    gem 'data_tasks'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install empty_gem

## Usage

To generate a data migration, use the rails generator:

    rails generate data_task MigrateSomeData

This will create:

    db/data_tasks/20120822023011_migrate_some_data.rb

Run all pending data tasks with rake:

    rake data:migrate

When re-building an empty development database with no data, you probably want to skip running the data tasks. To mark
all pending tasks complete:

    rake data:assume_migrated

## Common Problems

If you're running your Rails processes in threadsafe mode, you'll get errors about undefined
constants when trying to access model classes. You'll need to disable while running
rake tasks. In your environment file (ex. `config/environments/production.rb`), change:

    config.threadsafe!

to:

    config.threadsafe! unless $rails_rake_task

If you don't want to make that change, you can explicitly load the required model classes
inside the migration class, or define stub model classes. For example, if you wanted to
add a new SideHatch record in the migration, you could define:

    class SideHatch < ActiveRecord::Base; end

    class CreateSideHatch < ActiveRecord::Migration
{'fraction_non_alphanumeric': 0.04630575417092271, 'fraction_numerical': 0.009533537623425264, 'mean_word_length': 4.265232974910394, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5651086', 'n_tokens_mistral': 821, 'n_tokens_neox': 764, 'n_words': 382}