Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

DRY up the db auth strings

  • Loading branch information...
commit 631df4a087d65d83f01600ddba83f2a4fcfe6e23 1 parent 6e2e5de
Joost Baaij authored August 04, 2011
2  capistrano_transmit.gemspec
@@ -2,7 +2,7 @@
2 2
 
3 3
 Gem::Specification.new do |s|
4 4
   s.name = %q{capistrano_transmit}
5  
-  s.version = "0.2.9"
  5
+  s.version = "0.2.10"
6 6
 
7 7
   s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8 8
   s.authors = ["Joost Baaij"]
24  lib/capistrano/transmit.rb
@@ -15,10 +15,10 @@
15 15
     namespace :get do
16 16
       desc 'Fetch the remote production database and overwrite your local development database with it'
17 17
       task :mysql, :roles => :db do
18  
-        run "mysqldump --opt --quick --extended-insert --skip-lock-tables -u #{_db_remote['username']} --password='#{_db_remote['password']}' --host='#{_db_remote['host']}' #{_db_remote['database']} | gzip > #{dumpfile}"
  18
+        run "mysqldump --opt --quick --extended-insert --skip-lock-tables #{_remote_db_auth} | gzip > #{dumpfile}"
19 19
 
20 20
         system "rsync -vP #{_user_with_host}:#{dumpfile} tmp/#{_db_local["database"]}.sql.gz"
21  
-        system "gunzip < tmp/#{_db_local["database"]}.sql.gz | mysql -u #{_db_local['username']} --password='#{_db_local['password']}' --host='#{_db_local['host']}' #{_db_local['database']}"
  21
+        system "gunzip < tmp/#{_db_local["database"]}.sql.gz | mysql #{_local_db_auth}"
22 22
       end
23 23
 
24 24
       desc 'Fetch the assets from the production server to the development environment'
@@ -30,10 +30,10 @@
30 30
     namespace :put do
31 31
       desc 'Upload the local development database to the remote production database and overwrite it'
32 32
       task :mysql, :roles => :db do
33  
-        system "mysqldump --opt -u #{_db_local['username']} --password='#{_db_local['password']}' --host='#{_db_local['host']}' #{_db_local['database']} > tmp/#{_db_local['database']}.sql"
  33
+        system "mysqldump --opt #{_local_db_auth} > tmp/#{_db_local['database']}.sql"
34 34
 
35 35
         system "rsync -vP tmp/#{_db_local['database']}.sql #{_user_with_host}:#{dumpfile}"
36  
-        run "mysql -u #{_db_remote['username']} --password='#{_db_remote['password']}' --host='#{_db_remote['host']}' #{_db_remote['database']} < #{dumpfile}"
  36
+        run "mysql #{_remote_db_auth} < #{dumpfile}"
37 37
       end
38 38
     end
39 39
   
@@ -50,17 +50,27 @@ def _user_with_host
50 50
 
51 51
   # Output of the entire database.yml on the remote server.
52 52
   def _db_config
53  
-    @_db_config ||= capture("cat #{current_path}/config/database.yml")
  53
+    @_db_config       ||= capture("cat #{current_path}/config/database.yml")
54 54
   end
55 55
 
56 56
   # Production database configuration hash.
57 57
   def _db_remote
58  
-    @_db_remote ||= YAML::load(_db_config)['production']
  58
+    @_db_remote       ||= YAML::load(_db_config)['production']
59 59
   end
60 60
 
61 61
   # Development database configuration hash.
62 62
   def _db_local
63  
-    @_db_local ||= YAML::load_file("config/database.yml")['development']
  63
+    @_db_local        ||= YAML::load_file("config/database.yml")['development']
  64
+  end
  65
+  
  66
+  # Complete remote database connection string.
  67
+  def _remote_db_auth
  68
+    @_remote_db_auth  ||= "-u #{_db_remote['username']} --password='#{_db_remote['password']}' --host='#{_db_remote['host']}' #{_db_remote['database']}"
  69
+  end
  70
+
  71
+  # Complete local database connection string.
  72
+  def _local_db_auth
  73
+    @_local_db_auth   ||= "-u #{_db_local['username']} --password='#{_db_local['password']}' --host='#{_db_local['host']}' #{_db_local['database']}"
64 74
   end
65 75
   
66 76
 end

0 notes on commit 631df4a

Please sign in to comment.
Something went wrong with that request. Please try again.