Prev | Current Page 153 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


Managing Application Data
As mentioned previously, you can use any Ruby code within your migrations. Additionally,
when working within the Ruby on Rails framework, you??™re migrations will have full access to
all your models (and anything else in the base environment).
When the need arises to manipulate data in your application, such as the need to prepopulate
a new column with computed date (e.g., a column called total on a model Order that
holds the precomputed total of all of Order??™s LineItems), your first instinct may be to use your
models directly within the migrations to populate this new column. However, it is strongly
recommended that you not use your models directly inside your migrations. This is because
migrations are all about mitigating the problems that come from the differences among databases,
developers, and even the times in the same project.
Strictly speaking, you don??™t know when you??™ll need to change your models, so referencing
them in your migrations, while it could work out perfectly, may end up breaking the migration
process.


Pages:
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165