Seed A Database in Production Environment

48 views
Skip to first unread message

Carl-Erik Svensson

unread,
Aug 31, 2014, 12:00:06 AM8/31/14
to open...@googlegroups.com
Hi Gerald,

I took a bit of a break, but I'm just now getting back into the swing of things.  I haven't forgotten about the stats - will look into that soon - but I wanted to deploy my sample app on Heroku.  I was just wondering - how do you initialize the db for the web admin you have running on heroku?  

Everything is pretty simple with an sqlite3 databse, but heroku only supports Postgresql, so I'm trying to create a build script or Rake task to load various setups, but I don't know if I can install the different repositories (i.e. world.db, openfootball/major-league-soccer) on the heroku app, so I might not be able to give a local path to the data.  Is there a way to install from a Git URL?  Any other suggestions.

BTW, I looked at your talk on WebComponents - very interesting!

Thanks!
Carl

Gerald Bauer

unread,
Aug 31, 2014, 4:09:18 AM8/31/14
to open...@googlegroups.com
Hello,

Thanks for the update and thanks for keep going. I haven't
forgotten the stats - will try to add the missing FootballStatsReader.

To add football data on a heroku install you have at least two
options (a third easier one with zip archives is in planning):

Option 1) Never tried it put was successful if you check older
postings - e.g. install the data into your local postgress database
and than use pg dump or something and than load the copy into your
remote heroku postgres db.

Option 2) Add the datasets you want to load into your Gemfile -
that's how you get them onto the remote heroku machine. Example (see
the sport.db.admin Gemfile):


gem 'worlddb-data', '9.9.9', git: 'https://github.com/openmundi/world.db.git'

gem 'footballdb-data-national-teams', '9.9.9', git:
'https://github.com/openfootball/national-teams.git'
gem 'footballdb-data-world-cup', '9.9.9', git:
'https://github.com/openfootball/world-cup.git'

and so on.

Now you just need to code a litte rake build script (again see the
sport.db.admin sample task in db/seeds.rb ) e.g.

SportDb.read_builtin

sportdb_setups = [
['fr-france', '2014-15'],
['de-deutschland', '2014-15'],
['en-england', '2014-15'],
]

sportdb_setups.each do |setup|
SportDb.read_setup( "setups/#{setup[1]}",
find_data_path_from_gemfile_gitref( setup[0]) )
end

and than after you push your app to heroku you can use, for example:

$ heroku run rake db:seed

or something. That's all. Good luck. Cheers.

Carl-Erik Svensson

unread,
Aug 31, 2014, 9:08:44 PM8/31/14
to open...@googlegroups.com
Ah, that worked nicely!  I didn't realize you could point to non-gem git source in the Gemfile (like the data sets).  The only other gotcha I had was connecting to the right database, but with a rails app, you can simply require config/environment, and it will connect to proper database based on the RAILS_ENV, and require all the gems and libraries.  That made the Rakefile very easy to write.

Gerald Bauer

unread,
Sep 1, 2014, 3:12:11 AM9/1/14
to open...@googlegroups.com
Hello,

Wow. Looking great. Thanks for the update. Keep it up. Cheers.
Reply all
Reply to author
Forward
0 new messages