aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-10-10 22:43:42 -0700
committerVijay Dev <vijaydev.cse@gmail.com>2012-10-10 22:43:42 -0700
commitcd98c25ebedc27fe892468bb87ea260fb070f5eb (patch)
tree90e082fa88805977d9bada82484f1b2c43fb3403
parente5e174a302a06fa038c049bb64035f1a9fc4049b (diff)
parenta1d2f693776952e1f6ca7b347919047dbb4617f2 (diff)
downloadrails-cd98c25ebedc27fe892468bb87ea260fb070f5eb.tar.gz
rails-cd98c25ebedc27fe892468bb87ea260fb070f5eb.tar.bz2
rails-cd98c25ebedc27fe892468bb87ea260fb070f5eb.zip
Merge pull request #7050 from kytrinyx/documentation-reset-column-info
Expand the caveat about models in migrations in the rails guide.
-rw-r--r--guides/source/migrations.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/guides/source/migrations.md b/guides/source/migrations.md
index 67538b85e8..57db14f30c 100644
--- a/guides/source/migrations.md
+++ b/guides/source/migrations.md
@@ -889,6 +889,27 @@ class AddFuzzToProduct < ActiveRecord::Migration
end
```
+There are other ways in which the above example could have gone badly.
+
+For example, imagine that Alice creates a migration that selectively
+updates the +description+ field on certain products. She runs the
+migration, commits the code, and then begins working on the next feature,
+which is to add a new column +fuzz+ to the products table.
+
+She creates two migrations for this new feature, one which adds the new
+column, and a second which selectively updates the +fuzz+ column based on
+other product attributes.
+
+These migrations run just fine, but when Bob comes back from his vacation
+and calls `rake db:migrate` to run all the outstanding migrations, he gets a
+subtle bug: The descriptions have defaults, and the +fuzz+ column is present,
+but +fuzz+ is nil on all products.
+
+The solution is again to use +Product.reset_column_information+ before
+referencing the Product model in a migration, ensuring the Active Record's
+knowledge of the table structure is current before manipulating data in those
+records.
+
Schema Dumping and You
----------------------