Should I be updating database information in a migration?
I've been working on a rails project, in which I need to firstly seed the database and then update the data periodically.
The unfortunate problem is that I seem to want to update the same set of data multiple times. Hence I would like to use the same migration name...but the rails generator seems to complain about the naming.
This leads me to a couple of questions.
Should I even be using migrations to update data in my db or is there an alternative? How do I get around the naming problems, my assumption was that the timestamp that prepends itself to the migration name would be an adequa开发者_高级运维te differentiating factor?
Thanks
A while back developers used the migration for seeding data. Such was the importance of this need as a core feature and the perceived uncleanliness of this approach, Rails 2.3.4 introduced a dedicated rake task for doing this.
This is now best practice. See this post and this screencast for more info.
For periodic db updating you can add a custom rake task to lib/tasks
which works well in my experience.
精彩评论