From 022a5e8f74191e2dccaeb62abebbb939bcc8ad7b Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Mon, 14 Jan 2013 10:09:13 -0500 Subject: [PATCH 1/2] Update README.markdown Fixing Gemfile documentation --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index bd20cc7..00d5198 100644 --- a/README.markdown +++ b/README.markdown @@ -18,7 +18,7 @@ Install Add it as a gem: ```ruby - gem "capistrano-db-tasks", require: false + gem "capistrano-db-tasks", :require => false ``` Add to config/deploy.rb: From dfd1f2ef88087bd3ff04d0fb195fa35d2f765945 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Mon, 14 Jan 2013 11:34:49 -0500 Subject: [PATCH 2/2] Creating DB if it doesn't exist (currently only for mysql) --- lib/capistrano-db-tasks/database.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index aac49a1..73cf17f 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -52,6 +52,14 @@ def import_cmd(file) end end + def create_cmd + if mysql? + "mysql #{credentials} --execute \"CREATE DATABASE IF NOT EXISTS #{database};\"" + elsif postgresql? + # no idea about postgresql + end + end + end class Remote < Base @@ -78,6 +86,7 @@ def download(local_file = "#{output_file}") def load(file, cleanup) unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2')) # @cap.run "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} bundle exec rake db:drop db:create && #{import_cmd(unzip_file)}" + @cap.run "#{create_cmd}" @cap.run "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} && #{import_cmd(unzip_file)}" @cap.run("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup end @@ -94,6 +103,7 @@ def initialize(cap_instance) def load(file, cleanup) unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2')) # system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate") + system("#{create_cmd}") system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}") File.unlink(unzip_file) if cleanup end