Thanks Ryan.
By the way for those who use firefox you can increase the site width for this site using a style I created a while ago.
You can find it here.
http://userstyles.org/styles/15366
great screencast as always.
btw, what plugin do you use to nicely display db-records in console as a table?
@rwz he is using Hirb http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html
Thanks, Ryan!
It's indeed a very simple addition to rails, but it provides a good convention. I used to do this initial data loading on a custom rake task, normally called something like rake project:install, which would migrate the database and load initial data, including an admin user as well.
Thanks Ryan for another great episode. I think I can use it in my project. I am working on migrating legacy data from my postgres database to SQL server database with some added columns and schema changes. Can anyone tell me how can I accomplish this with some custom rake task? Can I use the concept in this episode to accomplish this. If yes, how do I read data from another database and insert it to my new database with some modification if needed?
My idea here is one this rake task is written, I can just run that rake task during deployment and get the data populated in the new database from the QA database.
I will appreciate your good suggestions.
What are your recommendations for sequential migrations that require seed data from previous migrations?
This generally only applies to legacy databases. I might need to move users from a legacy table to a new table and relate them to yet-to-be-seeded data (such as a default group).
Is it possible to have multiple seed files? And just reference them in the migration?
I love the new additions to rails, both 2.3 and 3.0; however this is NOT one of my favorites. I feel this feature was thrown in without a lot of thought about its uses. If you are doing incremental design and adding new features only as you need them, then this feature is outright broken.
For example, say I have a migration that creates an "issues" table and that table has a link to a status table on it. I use seeds.rb to insert "Open", "Closed" etc into the status table. Later I decided I need to add priority to issues and I add a priority table... wait how can I seed this table, seeds.rb has already been run and I don't want to reseed my status table, I may have user values in there now.
The only way I really see this working would be to add a seeds directory next to the migrations directory and create a seed file for each migration that gets run after the migration. Otherwise we will have to keep adding any seeds past the first into the migrations.
Good job, though I agree with rjordan about the usefulness of this particular feature. Also, perhaps it's time for captcha here? I don't know why, but it seems alot of rails blogs are cluttered with spam comments.
On the subject of seed data, I was wondering what is the best approach for accessing records in code. At present I use, for example...
def self.Pending() find(1); end
...inside my seeded models like OrderStatus. Then I can test using order.status == OrderStatus.Pending. The problem is that these class methods are evaluated when the environment loads, which is necessary to load seed data in the first place. It would also be nice to be able to cache these objects for the life of the application, as they are only referring to static data after all. Is there a more appropriate convention for this which maintains the readability of the code I have? Thanks!
Perfect timing, I has just been implementing fixtures for testing using another method, but obviously this is just great.
Thanks Ryan!
I think the countries seed should use
Country.find_or_create_by_name_and_code(name, code)
so that you don't delete the countries that are referenced by other tables (if you chose to do that)
So if you call Country.delete_all won't the break all previous associations! Unless your index is based on country code which should be noted in the migration creation.
OK, so with seed-fu, rake db:seed RAILS_ENV=test would seed the test database. With the builtin method, it doesn't. How do I get seed data into the test environment?
(Yes, it needs to be there — there's a validates_existence_of that depends on the seed data being loaded…)
Great railscast as usual.
Just one suggestion. For lists of countries and states, the Carmen gem is way better than copy-and-pasting:
http://github.com/jim/carmen
You also get some handy helpers to convert between full name and abbreviation.
Ryan Boa Tarde!
Estou usando o código a seguir para popular algumas tabelas:
http://pastie.org/650693
Ocorre que se executar mais de uma vez, a sequence do postgres continua. Como poderia fazer para resetar a sequence sempre que rodar rake db:seed ???
Abraços
Use rake
db:seed SEED='file_matching_ pattern'
for specific file to populate the database.
Enjoy and do not again repeatedly update all the seed_fu dependent tables again and again
Hi ryan.
I've created a plugin to seed data acording to the environment being loaded.
I've been using it to seed testing, staging and production databases with different kinds of data without having a big seeds.rb.
Check it out!
http://github.com/franciscotufro/environmental_seeder
Hey you have written a detailed analysis about this topic,I wonder how and where you get this information from. I would like to know more about the same . Would really appreciate if I could get more insights about this.
Wow Ryan, that's a lot of spam you've managed to harvest. :-) Perhaps a CAPTCHA of some sort might be in order?
I hope my clicking those links for you at least puts them in a queue so you can "delete all".
I want to say very thank you for this great informations. now i understand about it. Thank you !xc
web tasarımı, kurumsal site tasarımı, profesyonel web sitesi tasarımı, profesyonel web tasarımı
<a href="http://www.webtasarimturk.net" title="web tasarımı">web tasarımı</a>
great website,have very interested articles ,i have visit 'em ,to bekam more and more info!!!!!!!!!!!!!!!!!
i, interesting post. I have been pondering this topic,so thanks for writing. I'll probably be coming back to your blog...<a href="http://www.webtasarimturk.net" title="web tasarımı">web tasarımı</a>
great website,have very interested articles ,i have visit 'em ,to bekam more and more info
eat website,have very interested articles ,i have visit 'em
What would the code look like to read the codes.csv file in db/seedData directory? It has three columns. name, date, location
Thank you!!
I was virtuous browsing for relevant blog posts for my cast investigate and I happened to falter upon yours. Thanks for the functional accumulation!
I really appreciate what you post. Thank you for its - much help in decision of my problems
The blog article very surprised to me! Your writing is good. In this I learned a lot! Thank you!
The information you provided was very useful. Because of your help, thank you
Manchester City celebrated owner Sheikh Mansour's first visit to Eastlands by delivering an impressive performance to cruise to victory against Liverpool.
Sheikh Mansour has changed the face of Manchester City since his takeover two years ago - and this latest expensively reconstructed version of Roberto Mancini's squad provided evidence that they may be able to meet the expectations that will accompany his huge financial outlay.
The info is useful.thanks great. I like your information so much. It is something worth appreciating by us. It is very kind thing to see your wonderful post! I perfectly agree with you! That should always be the case.
Discount Wholesale Electronics, Wholesale Cell Phones, Electronic Gadgets and More from the Best Dropship Wholesaler
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
Manchester City since his takeover two years ago - and this latest expensively reconstructed version of Roberto Mancini's squad provided evidence that they may be able to meet the expectations that will accompany his huge financial outlay.
Good article! Thank you so much for sharing this post.Your views truly open my mind.






