Adam
asked this on May 29, 2011 11:56
I'm working my way through the Depot app from 'Agile Web Development with Rails'. I've figured out how to deploy to Cloud Foundry (finally got all my gem dependencies right and performed a 'bundle package' prior to 'vmc update...').
Now I'm wondering if there's anyway to populate the sample data, (in my db/seeds.rb file) from my development environment to cloud foundry. This would typically be done using 'rake db:seed'. Anyway to have this command run against Cloud Foundry?
Thanks,
Comments
You could try invoking `rake db:seed` from within your app on startup if the database is empty. This could be put in an initializer. Just a guess, my invite has not come through yet.
For example:
Does that answer your question?
Thank you both, that did answer my question. The data loader approach worked.
It would be nice if there were some way of issuing rake commands through the vmc application, kind of like in heroku:
http://devcenter.heroku.com/articles/rake
I had some issues doing that. The application could load perfectly without the data loader but as soon as I introduced the data loader I ran into problems.
From terminal:
...
Stopping Application: OK
Staging Application: OK
Starting Application: .......Error: Application 'meddiesite's state is undetermined, not enough information available.
Were there any require's that were needed in the Rakefile? I might have been missing something else. My application is on github... (https://github.com/bwu/AcapocoNewbieRailsSite ). I didn't include the data_loader.rb file since it wouldn't load to cloud foundry with it.
Hi Brian,
After testing your application and looking at output from 'vmc files <appname> logs/migration.log', I found that the DB migrations haven't finished running before data_loader.rb is called. In migration.log you'll see an error about the table current_members not existing. There are a couple options:
1. Add the seed data to the relevant migration. For example, add the following in db/migrate/20110722213133_create_current_members.rb after create_table:
2. Create an action to seed the DB from a URL.
Add to app/routes.rb:
Add to app/controllers/application_controller.rb:
Then point your browser to appname.cloudfoundry.com/seed.
Thanks for your help. I added all of my data in the migrations and everything is running smoothly.
I didn't get the 2nd option to work because of two before_filters that I put in the application_controller. With a little more troubleshooting I'm sure it would have worked fine, but I wanted the databases to be full upon launching.
Thanks again. Cloud foundry is great.
Just ran into the same issue. I make extesnsive use of seeding database during testing and also for productions / demo sites.
It would be really nice to have control over that from the vmc command line, e.g.
vmc rake app_name db:seed
or something like that, so I don't have to write a controller, just to be able to run rake tasks....
Hi Thomas,
Cloud Foundry Engineering is aware of the issue, but we don't have an ETA yet on when this might be available. Stay tuned.
Thanks Glenn,
Looking forward to the fix.
Thomas
I have the same question. Trying to get a rails app working where we use sunspot gem with solr. Need to do rake sunspot:solr:reindex in different environments.
To seed your DB, we recommend using Caldecott to set up a tunnel from your local dev machine to the remote Cloud Foundry service: http://blog.cloudfoundry.com/post/12928974099/now-you-can-tunnel-in...
Once the tunnel is established, you'll be given connection information that you can supply to your app's DB config, and tasks like 'rake db:seed' should work.