Just after a ‘best-practise’ recommendation here really, I am
deploying a series of applications to EY and for each one, need to
setup the database with some default settings / user account etc etc.
What is the best way to write a few initial rows to a vanilla
database? I’ve looked into using the deploy hooks on EY but it doesn’t
seem to cover DB interaction. . .
I know I could create a standard backup file and restore this each
time but it feels like there should be a better way!
When you deploy you can specify a migration task. By default it is “rake
db:migrate”. For your new applications, try “rake db:migrate db:seed”,
db:seed is the Rails 3 hook for setting up new database content.
Remember to change your migration field back to “rake db:migrate” after
first successful deploy, other wise you will re-seed again and again
Great - just what I was looking for with the db:seed command - thanks
However you wish to load data, the migration task can take a command and
it’s output is included in the deploy logs.
Here’s a blog post I wrote on this subject with some sample code. It
covers the difference between loading ‘seed’ data which is intended to
live as a permanent part of the production database (for example, role
names or state codes) and loading sample data just used for testing
*for example, fake test accounts).
Hopefully it’ll help. There’s some sample code in the post.