Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 6 create db if it doesn't exist #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down