diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2011-06-06 02:10:31 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2011-06-06 02:10:38 +0530 |
commit | a2cf91a1a4382869aaff7d7b0fbbb60336a3c830 (patch) | |
tree | daffe5534d5d0ed46d24f3f4581014832c490f06 /railties | |
parent | e1b202fc70196ee6520e0870df539b48c4a76d1e (diff) | |
download | rails-a2cf91a1a4382869aaff7d7b0fbbb60336a3c830.tar.gz rails-a2cf91a1a4382869aaff7d7b0fbbb60336a3c830.tar.bz2 rails-a2cf91a1a4382869aaff7d7b0fbbb60336a3c830.zip |
minor edits in migrations guide
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/migrations.textile | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index d60b68ec7f..f17f686d47 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -55,6 +55,8 @@ class AddReceiveNewsletterToUsers < ActiveRecord::Migration end </ruby> +NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations. + This migration adds a +receive_newsletter+ column to the +users+ table. We want it to default to +false+ for new users, but existing users are considered to have already opted in, so we use the User model to set the flag to +true+ for existing users. @@ -73,11 +75,9 @@ class CreateProducts < ActiveRecord::Migration end </ruby> -NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations. - h4. Migrations are Classes -A migration is a subclass of <tt>ActiveRecord::Migration</tt> that implements two class methods: +up+ (perform the required transformations) and +down+ (revert them). +A migration is a subclass of <tt>ActiveRecord::Migration</tt> that implements two methods: +up+ (perform the required transformations) and +down+ (revert them). Active Record provides methods that perform common data definition tasks in a database independent way (you'll read about them in detail later): @@ -115,7 +115,7 @@ h4. Changing Migrations Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run +rake db:migrate+. You must rollback the migration (for example with +rake db:rollback+), edit your migration and then run +rake db:migrate+ to run the corrected version. -In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. Just use some common sense. +In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. h3. Creating a Migration |