Skip to content

Commit

Permalink
auto-migrate, closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
holman committed Oct 29, 2011
1 parent dfdaf4b commit 8411e5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -49,9 +49,7 @@ GitHub](https://github.com/holman/play/blob/master/play.yml.example).

This is a bit of a pain that we'll correct eventually. For now, create your
MySQL database by hand. We expect the database to be called `play`, but it's
really pulled from whatever you have in `~/.play.yml`. When that's set up, run:

bin/play --migrate
really pulled from whatever you have in `~/.play.yml`.

### Set up your GitHub application

Expand Down
15 changes: 10 additions & 5 deletions bin/play
Expand Up @@ -5,20 +5,23 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'play'
require 'optparse'

# Auto-migrate before launching the servers.
def migrate
ActiveRecord::Base.establish_connection(Play.config['db'])
ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../db/migrate/", ActiveRecord::Migrator.current_version)
end

parser = OptionParser.new do |opts|
opts.banner = "Usage: play [options] COMMAND"

opts.separator ""
opts.separator "Options:"

opts.on("--migrate", "Setup the database") do
ActiveRecord::Base.establish_connection(Play.config['db'])
ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../db/migrate/", ActiveRecord::Migrator.current_version)
end

opts.on("-d", "--detach", "Start the music server") do
ENV['RACK_ENV'] = 'production'

migrate

# Run a "quick" import to check for anything new.
pid = fork { Play::Library.import_songs }
Process.detach(pid)
Expand All @@ -32,6 +35,8 @@ parser = OptionParser.new do |opts|
end

opts.on("-w", "--web", "Run the web instance") do
migrate

pid = fork { Play::Library.monitor }
Process.detach(pid)
system("unicorn -c #{File.dirname(__FILE__)}/../config/unicorn.rb")
Expand Down

0 comments on commit 8411e5a

Please sign in to comment.