From 8411e5a697ebd5381592f863c41b4028b742e7c6 Mon Sep 17 00:00:00 2001 From: Zach Holman Date: Fri, 28 Oct 2011 21:33:48 -0700 Subject: [PATCH] auto-migrate, closes #10 --- README.md | 4 +--- bin/play | 15 ++++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c370df59..149f9da8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/play b/bin/play index d1d0cc9d..34b40df4 100755 --- a/bin/play +++ b/bin/play @@ -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) @@ -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")