capistrano-mysqldump 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +3 -12
- data/Gemfile.lock +39 -18
- data/{README → README.md} +54 -11
- data/Rakefile +4 -21
- data/VERSION +1 -1
- data/capistrano-mysqldump.gemspec +16 -39
- data/lib/capistrano/mysqldump.rb +119 -52
- data/test/helper.rb +1 -3
- data/test/test_capistrano-mysqldump.rb +36 -2
- metadata +38 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6171de0702d5184a3710a25fd7905a5fcedf316
|
4
|
+
data.tar.gz: 89494639809fcf9b4c8bee140f188172e709243d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bb26ab73f303dfc7846642680ae01b678998f7893be1daf0dd1037aeee3d1bb07528762582b33858fcc1b5d13c4c5e4b4efbf10963984d8fcbef5f47ec8d5b5
|
7
|
+
data.tar.gz: 78f4899c94b6a75fb5359ee76df9f5d7d58fd9a69fd304fbc88cb7bed63f73a9ac7ed834985fe4d0f2b00f41ad1428c0f6b0103b86eac31957c28151fc9f06e4
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
1.1.2 - 2014-10-06
|
2
|
+
==================
|
3
|
+
|
4
|
+
## features
|
5
|
+
[can ignore tables during dump](https://github.com/alexfarrill/capistrano-mysqldump/pull/6)
|
6
|
+
[can set arbitrary params and dump tables](https://github.com/alexfarrill/capistrano-mysqldump/pull/8/files)
|
7
|
+
|
8
|
+
## bug fixes
|
9
|
+
[logic to determine local vs remove dump was backwards](https://github.com/alexfarrill/capistrano-mysqldump/pull/10)
|
10
|
+
|
11
|
+
## style & finesse
|
12
|
+
|
13
|
+
[fixed readme formatting](https://github.com/alexfarrill/capistrano-mysqldump/pull/5)
|
14
|
+
[setup test env](https://github.com/alexfarrill/capistrano-mysqldump/pull/7)
|
data/Gemfile
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
source
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source 'https://rubygems.org'
|
5
2
|
|
6
|
-
gem
|
7
|
-
|
8
|
-
# Add dependencies to develop your gem here.
|
9
|
-
# Include everything needed to run rake, tests, features, etc.
|
10
|
-
group :development do
|
11
|
-
gem "bundler", "~> 1.0.0"
|
12
|
-
gem "jeweler", "~> 1.6.4"
|
13
|
-
end
|
3
|
+
# Specify your gem's dependencies in capistrano-mysqldump.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
capistrano-mysqldump (1.1.2)
|
5
|
+
capistrano (>= 1.0.0)
|
6
|
+
|
1
7
|
GEM
|
2
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
3
9
|
specs:
|
4
|
-
|
10
|
+
activesupport (4.0.1)
|
11
|
+
i18n (~> 0.6, >= 0.6.4)
|
12
|
+
minitest (~> 4.2)
|
13
|
+
multi_json (~> 1.3)
|
14
|
+
thread_safe (~> 0.1)
|
15
|
+
tzinfo (~> 0.3.37)
|
16
|
+
atomic (1.1.14)
|
17
|
+
capistrano (2.15.5)
|
5
18
|
highline
|
6
19
|
net-scp (>= 1.0.0)
|
7
20
|
net-sftp (>= 2.0.0)
|
8
21
|
net-ssh (>= 2.0.14)
|
9
22
|
net-ssh-gateway (>= 1.1.0)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
net-
|
17
|
-
net-ssh (>=
|
18
|
-
net-
|
19
|
-
|
20
|
-
|
21
|
-
net-ssh-gateway (1.1.0)
|
22
|
-
net-ssh (>= 1.99.1)
|
23
|
+
highline (1.6.20)
|
24
|
+
i18n (0.6.5)
|
25
|
+
minitest (4.7.5)
|
26
|
+
multi_json (1.8.2)
|
27
|
+
net-scp (1.1.2)
|
28
|
+
net-ssh (>= 2.6.5)
|
29
|
+
net-sftp (2.1.2)
|
30
|
+
net-ssh (>= 2.6.5)
|
31
|
+
net-ssh (2.7.0)
|
32
|
+
net-ssh-gateway (1.2.0)
|
33
|
+
net-ssh (>= 2.6.5)
|
23
34
|
rake (0.9.2.2)
|
35
|
+
shoulda (3.5.0)
|
36
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
37
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
38
|
+
shoulda-context (1.1.6)
|
39
|
+
shoulda-matchers (2.4.0)
|
40
|
+
activesupport (>= 3.0.0)
|
41
|
+
thread_safe (0.1.3)
|
42
|
+
atomic
|
43
|
+
tzinfo (0.3.38)
|
24
44
|
|
25
45
|
PLATFORMS
|
26
46
|
ruby
|
27
47
|
|
28
48
|
DEPENDENCIES
|
29
|
-
bundler (~> 1.
|
30
|
-
capistrano
|
31
|
-
|
49
|
+
bundler (~> 1.3)
|
50
|
+
capistrano-mysqldump!
|
51
|
+
rake
|
52
|
+
shoulda
|
data/{README → README.md}
RENAMED
@@ -1,46 +1,89 @@
|
|
1
|
-
|
1
|
+
# capistrano-mysqldump
|
2
2
|
|
3
3
|
Capistrano extension to run mysqldump remotely, download, and import into your local Rails development database.
|
4
4
|
|
5
5
|
WARNING: This will blow away your development database (duh)
|
6
6
|
|
7
|
-
|
7
|
+
## Installation
|
8
8
|
|
9
|
+
```ruby
|
9
10
|
gem install capistrano-mysqldump
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
## Usage
|
12
14
|
|
13
15
|
* In your deploy file:
|
14
16
|
|
17
|
+
```ruby
|
15
18
|
require 'capistrano/mysqldump'
|
19
|
+
```
|
16
20
|
|
17
21
|
* Run:
|
18
22
|
|
23
|
+
```ruby
|
19
24
|
cap mysqldump
|
25
|
+
```
|
20
26
|
|
21
|
-
Or if you're using capistrano-ext/multistage
|
27
|
+
Or if you're using `capistrano-ext/multistage`, do
|
22
28
|
|
29
|
+
```ruby
|
23
30
|
cap production mysqldump
|
31
|
+
```
|
24
32
|
|
25
33
|
Or whatever environment you want to take the mysqldump from
|
26
34
|
|
27
|
-
|
35
|
+
## Configuration
|
28
36
|
|
29
|
-
Override these defaults in deploy.rb if necessary
|
37
|
+
Override these defaults in `deploy.rb` if necessary
|
30
38
|
|
31
|
-
* Location of the mysqldump binary
|
39
|
+
* Location of the mysqldump binary (default is `which mysqldump`)
|
40
|
+
|
41
|
+
```ruby
|
32
42
|
set :mysqldump_bin, "/usr/local/mysql/bin/mysqldump"
|
43
|
+
```
|
33
44
|
|
34
45
|
* Where on the remote machine to dump the sql dump file
|
46
|
+
|
47
|
+
```ruby
|
35
48
|
set :mysqldump_remote_tmp_dir, "/tmp"
|
49
|
+
```
|
36
50
|
|
37
51
|
* Where on the local machine to download the sql dump file from the remote machine
|
52
|
+
|
53
|
+
```ruby
|
38
54
|
set :mysqldump_local_tmp_dir, "/tmp"
|
55
|
+
```
|
39
56
|
|
40
|
-
* Where to run the mysqldump command.
|
57
|
+
* Where to run the mysqldump command. If set to `:local`, mysqldump will use the `-h` parameter and run the dump locally. The default is set to `:local` if a host is specified, otherwise it is set to `:remote`
|
58
|
+
|
59
|
+
```ruby
|
41
60
|
set :mysqldump_location, :local
|
61
|
+
```
|
62
|
+
|
63
|
+
* The tables to ignore during the dump
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
set :mysqldump_ignore_tables, %w(logs page_views)
|
67
|
+
```
|
68
|
+
|
69
|
+
* Or the tables to extract
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
set :mysqldump_tables, %w{cool_info totally_awesome_rows}
|
73
|
+
```
|
74
|
+
(default is all tables)
|
75
|
+
|
76
|
+
* Arbitrary options to pass to mysql dump
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
set :mysqldump_options, {'no-data' => true, 'port' => 3307 }}
|
80
|
+
```
|
81
|
+
|
82
|
+
Equivalent to running
|
83
|
+
|
84
|
+
$ mysqldump --no-data --port=3308
|
42
85
|
|
43
|
-
|
86
|
+
## Contributing to capistrano-mysqldump
|
44
87
|
|
45
88
|
* Contributions welcome
|
46
89
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
@@ -51,7 +94,7 @@ set :mysqldump_location, :local
|
|
51
94
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
52
95
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
53
96
|
|
54
|
-
|
97
|
+
## Copyright
|
55
98
|
|
56
99
|
Copyright (c) 2011 Alex Farrill. See LICENSE.txt for
|
57
|
-
further details.
|
100
|
+
further details.
|
data/Rakefile
CHANGED
@@ -1,29 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
3
|
begin
|
6
|
-
|
7
|
-
rescue
|
8
|
-
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
11
7
|
end
|
12
|
-
require 'rake'
|
13
8
|
|
14
|
-
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "capistrano-mysqldump"
|
18
|
-
gem.homepage = "http://github.com/alexfarrill/capistrano-mysqldump"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Capistrano extension to run mysqldump remotely, download, and import into your local Rails development database}
|
21
|
-
gem.description = %Q{}
|
22
|
-
gem.email = "alex.farrill@gmail.com"
|
23
|
-
gem.authors = ["Alex Farrill"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
9
|
+
Bundler::GemHelper.install_tasks
|
27
10
|
|
28
11
|
require 'rake/testtask'
|
29
12
|
Rake::TestTask.new(:test) do |test|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
@@ -1,55 +1,32 @@
|
|
1
|
-
#
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
1
|
+
# coding: utf-8
|
6
2
|
Gem::Specification.new do |s|
|
7
3
|
s.name = "capistrano-mysqldump"
|
8
|
-
s.version = "1.1.
|
4
|
+
s.version = "1.1.2"
|
9
5
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
6
|
s.authors = ["Alex Farrill"]
|
12
7
|
s.date = "2013-07-03"
|
13
8
|
s.description = ""
|
14
9
|
s.email = "alex.farrill@gmail.com"
|
15
10
|
s.extra_rdoc_files = [
|
16
11
|
"LICENSE.txt",
|
17
|
-
"README"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
|
-
"LICENSE.txt",
|
23
|
-
"README",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"capistrano-mysqldump.gemspec",
|
27
|
-
"lib/capistrano/mysqldump.rb",
|
28
|
-
"test/helper.rb",
|
29
|
-
"test/test_capistrano-mysqldump.rb"
|
12
|
+
"README.md"
|
30
13
|
]
|
14
|
+
|
15
|
+
s.files = Dir["lib/**/*"]
|
16
|
+
|
17
|
+
# explicitly disable test files until they're used
|
18
|
+
# s.test_files = Dir['test/**/*']
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split($/)
|
31
21
|
s.homepage = "http://github.com/alexfarrill/capistrano-mysqldump"
|
32
22
|
s.licenses = ["MIT"]
|
33
23
|
s.require_paths = ["lib"]
|
34
24
|
s.rubygems_version = "1.8.25"
|
35
25
|
s.summary = "Capistrano extension to run mysqldump remotely, download, and import into your local Rails development database"
|
36
26
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
44
|
-
else
|
45
|
-
s.add_dependency(%q<capistrano>, [">= 1.0.0"])
|
46
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
48
|
-
end
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<capistrano>, [">= 1.0.0"])
|
51
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
27
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
28
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 1.0.0"])
|
29
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
30
|
+
s.add_development_dependency "rake"
|
31
|
+
s.add_development_dependency "shoulda"
|
32
|
+
end
|
data/lib/capistrano/mysqldump.rb
CHANGED
@@ -1,68 +1,135 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Mysqldump
|
5
|
+
|
6
|
+
# converts a hash of options into a string.
|
7
|
+
# drops falsey-valued keys.
|
8
|
+
#
|
9
|
+
# `{u: 'foo', 'single-transaction' => true, ignore-tables' => 'bar', p: nil}`
|
10
|
+
# => '-ufoo --ignore-tables=bar --single-transaction
|
11
|
+
#
|
12
|
+
def self.options_string(options = nil)
|
13
|
+
options
|
14
|
+
options.map do |k,v|
|
15
|
+
next unless v
|
16
|
+
used_value = v == true ? nil : v
|
17
|
+
used_prefix, used_join = if k.length == 1
|
18
|
+
["-", '']
|
19
|
+
else
|
20
|
+
["--", '=']
|
21
|
+
end
|
22
|
+
|
23
|
+
"#{used_prefix}#{[k, used_value].compact.join used_join}"
|
24
|
+
end.compact.join ' '
|
25
|
+
end
|
8
26
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
set :mysqldump_remote_tmp_dir, "/tmp" unless exists?(:mysqldump_remote_tmp_dir)
|
16
|
-
set :mysqldump_local_tmp_dir, "/tmp" unless exists?(:mysqldump_local_tmp_dir)
|
17
|
-
set :mysqldump_location, host && !host.empty? && host != "localhost" ? :local : :remote unless exists?(:mysqldump_location)
|
18
|
-
|
19
|
-
# for convenience
|
20
|
-
set :mysqldump_filename, "%s-%s.sql" % [application, Time.now.to_i]
|
21
|
-
set :mysqldump_filename_gz, "%s.gz" % mysqldump_filename
|
22
|
-
set :mysqldump_remote_filename, File.join( mysqldump_remote_tmp_dir, mysqldump_filename_gz )
|
23
|
-
set :mysqldump_local_filename, File.join( mysqldump_local_tmp_dir, mysqldump_filename )
|
24
|
-
set :mysqldump_local_filename_gz, File.join( mysqldump_local_tmp_dir, mysqldump_filename_gz )
|
27
|
+
# returns credential options for a given username and password
|
28
|
+
# when given an empty or nil password, does not include p: in the returned hash
|
29
|
+
def self.credential_options(username, password)
|
30
|
+
{}.tap do |opts|
|
31
|
+
opts[:u] = username
|
32
|
+
opts[:p] = password if password == true || password && !password.empty?
|
25
33
|
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.load_into(configuration)
|
37
|
+
configuration.load do
|
38
|
+
namespace :mysqldump do
|
39
|
+
task :default, :roles => :db do
|
40
|
+
dump
|
41
|
+
import
|
42
|
+
end
|
43
|
+
|
44
|
+
task :setup do
|
45
|
+
@mysqldump_config = fetch :mysqldump_config, YAML.load_file("config/database.yml")[rails_env.to_s]
|
46
|
+
unless @mysqldump_config
|
47
|
+
raise "Cannot load database config for #{rails_env} environment"
|
48
|
+
end
|
26
49
|
|
27
|
-
|
28
|
-
setup
|
29
|
-
username, password, database, host = mysqldump_config.values_at *%w( username password database host )
|
50
|
+
host = @mysqldump_config["host"]
|
30
51
|
|
31
|
-
|
32
|
-
|
52
|
+
# overwrite these if necessary
|
53
|
+
@mysqldump_bin = fetch :mysqldump_bin, "`which mysqldump`"
|
54
|
+
mysqldump_remote_tmp_dir = fetch :mysqldump_remote_tmp_dir, "/tmp"
|
55
|
+
mysqldump_local_tmp_dir = fetch :mysqldump_local_tmp_dir, "/tmp"
|
56
|
+
@mysqldump_location = fetch :mysqldump_location, host && !host.empty? && host != "localhost" ? :remote : :local
|
57
|
+
@mysqldump_options = fetch :mysqldump_options, {}
|
33
58
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
59
|
+
# for convenience
|
60
|
+
mysqldump_filename = "%s-%s.sql" % [application, Time.now.to_i]
|
61
|
+
mysqldump_filename_gz = "%s.gz" % mysqldump_filename
|
62
|
+
@mysqldump_remote_filename = File.join( mysqldump_remote_tmp_dir, mysqldump_filename_gz )
|
63
|
+
@mysqldump_local_filename = File.join( mysqldump_local_tmp_dir, mysqldump_filename )
|
64
|
+
@mysqldump_local_filename_gz = File.join( mysqldump_local_tmp_dir, mysqldump_filename_gz )
|
38
65
|
|
39
|
-
|
40
|
-
|
66
|
+
@mysqldump_ignore_tables = fetch :mysqldump_ignore_tables, []
|
67
|
+
@mysqldump_tables = fetch :mysqldump_tables, []
|
41
68
|
end
|
42
69
|
|
43
|
-
|
44
|
-
|
70
|
+
def default_options
|
71
|
+
setup
|
72
|
+
username, password, host = @mysqldump_config.values_at *%w( username password host )
|
73
|
+
{
|
74
|
+
:h => host,
|
75
|
+
:quick => true,
|
76
|
+
"single-transaction" => true,
|
77
|
+
}.tap do |options|
|
45
78
|
|
46
|
-
|
47
|
-
when :local
|
48
|
-
mysqldump_cmd += " -u %s" % username
|
49
|
-
mysqldump_cmd += " -p#{password}" if password && !password.empty?
|
50
|
-
mysqldump_cmd += " %s > %s" % [ database, mysqldump_local_filename]
|
79
|
+
password = true if @mysqldump_location == :remote
|
51
80
|
|
52
|
-
|
53
|
-
|
54
|
-
|
81
|
+
if @mysqldump_ignore_tables.any?
|
82
|
+
options['ignore-tables'] = [@mysqldump_ignore_tables].flatten.join ' '
|
83
|
+
end
|
84
|
+
|
85
|
+
options.merge! Mysqldump.credential_options(username, password)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
task :dump, :roles => :db do
|
92
|
+
options = default_options
|
93
|
+
options.merge! @mysqldump_options
|
94
|
+
password, database = @mysqldump_config.values_at *%w( password database )
|
95
|
+
mysqldump_cmd = "#{@mysqldump_bin} #{Mysqldump.options_string(options)} #{database} #{[@mysqldump_tables].flatten.compact.join ' '}"
|
96
|
+
|
97
|
+
case @mysqldump_location
|
98
|
+
when :remote
|
99
|
+
mysqldump_cmd += " | gzip > %s" % @mysqldump_remote_filename
|
100
|
+
|
101
|
+
run mysqldump_cmd do |ch, stream, out|
|
102
|
+
ch.send_data "#{password}\n" if out =~ /^Enter password:/
|
103
|
+
end
|
104
|
+
|
105
|
+
download @mysqldump_remote_filename, @mysqldump_local_filename_gz, :via => :scp
|
106
|
+
run "rm #{@mysqldump_remote_filename}"
|
55
107
|
|
56
|
-
|
57
|
-
|
58
|
-
|
108
|
+
`gunzip #{@mysqldump_local_filename_gz}`
|
109
|
+
when :local
|
110
|
+
mysqldump_cmd += " > %s" % @mysqldump_local_filename
|
59
111
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
112
|
+
`#{mysqldump_cmd}`
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
task :import do
|
117
|
+
config = YAML.load_file("config/database.yml")["development"]
|
118
|
+
username, password, database = config.values_at *%w( username password database )
|
119
|
+
|
120
|
+
credentials_string = Mysqldump.options_string Mysqldump.credential_options(username, password)
|
121
|
+
|
122
|
+
mysql_cmd = "mysql #{credentials_string}"
|
123
|
+
`#{mysql_cmd} -e "drop database #{database}; create database #{database}"`
|
124
|
+
`#{mysql_cmd} #{database} < #{@mysqldump_local_filename}`
|
125
|
+
`rm #{@mysqldump_local_filename}`
|
126
|
+
end
|
127
|
+
end
|
65
128
|
end
|
66
129
|
end
|
67
130
|
end
|
131
|
+
end
|
132
|
+
|
133
|
+
if Capistrano::Configuration.instance
|
134
|
+
Capistrano::Mysqldump.load_into(Capistrano::Configuration.instance)
|
68
135
|
end
|
data/test/helper.rb
CHANGED
@@ -10,9 +10,7 @@ end
|
|
10
10
|
require 'test/unit'
|
11
11
|
require 'shoulda'
|
12
12
|
|
13
|
-
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'capistrano-mysqldump'
|
13
|
+
require File.expand_path('../../lib/capistrano/mysqldump', __FILE__)
|
16
14
|
|
17
15
|
class Test::Unit::TestCase
|
18
16
|
end
|
@@ -1,7 +1,41 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
|
3
4
|
class TestCapistranoMysqldump < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
5
|
+
mysqldump = Capistrano::Mysqldump
|
6
|
+
|
7
|
+
context '.options_string' do
|
8
|
+
should "not include falesy values" do
|
9
|
+
assert_equal '', mysqldump.options_string({:a => nil, :b => false})
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'use "--" prefix and "=" join for length > 1 keys' do
|
13
|
+
assert_equal '--multi_char_key=foo', mysqldump.options_string(:multi_char_key => 'foo')
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'use "-" prefix and "" join for length == 1 keys' do
|
17
|
+
assert_equal '-ofoo', mysqldump.options_string({:o => 'foo'})
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'not include variable for value = true' do
|
21
|
+
assert_equal '-o --multi_char_key', mysqldump.options_string(:o => true, :multi_char_key => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '.credential_options(username, password)' do
|
26
|
+
should 'includes password if it exists' do
|
27
|
+
assert_equal(
|
28
|
+
{:u => 'foo', :p => 'bar'},
|
29
|
+
mysqldump.credential_options('foo', 'bar')
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'does not include password if falsey or empty' do
|
34
|
+
assert_equal(
|
35
|
+
{:u => 'foo'},
|
36
|
+
mysqldump.credential_options('foo', ''),
|
37
|
+
mysqldump.credential_options('foo', false)
|
38
|
+
)
|
39
|
+
end
|
6
40
|
end
|
7
41
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-mysqldump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alex Farrill
|
@@ -14,63 +13,73 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: capistrano
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.
|
33
|
+
version: '1.3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
40
|
+
version: '1.3'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
62
69
|
description: ''
|
63
70
|
email: alex.farrill@gmail.com
|
64
71
|
executables: []
|
65
72
|
extensions: []
|
66
73
|
extra_rdoc_files:
|
67
74
|
- LICENSE.txt
|
68
|
-
- README
|
75
|
+
- README.md
|
69
76
|
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- CHANGELOG.md
|
70
79
|
- Gemfile
|
71
80
|
- Gemfile.lock
|
72
81
|
- LICENSE.txt
|
73
|
-
- README
|
82
|
+
- README.md
|
74
83
|
- Rakefile
|
75
84
|
- VERSION
|
76
85
|
- capistrano-mysqldump.gemspec
|
@@ -80,30 +89,28 @@ files:
|
|
80
89
|
homepage: http://github.com/alexfarrill/capistrano-mysqldump
|
81
90
|
licenses:
|
82
91
|
- MIT
|
92
|
+
metadata: {}
|
83
93
|
post_install_message:
|
84
94
|
rdoc_options: []
|
85
95
|
require_paths:
|
86
96
|
- lib
|
87
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
98
|
requirements:
|
90
|
-
- -
|
99
|
+
- - ">="
|
91
100
|
- !ruby/object:Gem::Version
|
92
101
|
version: '0'
|
93
|
-
segments:
|
94
|
-
- 0
|
95
|
-
hash: -757547364320712607
|
96
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
103
|
requirements:
|
99
|
-
- -
|
104
|
+
- - ">="
|
100
105
|
- !ruby/object:Gem::Version
|
101
106
|
version: '0'
|
102
107
|
requirements: []
|
103
108
|
rubyforge_project:
|
104
|
-
rubygems_version:
|
109
|
+
rubygems_version: 2.2.2
|
105
110
|
signing_key:
|
106
|
-
specification_version:
|
111
|
+
specification_version: 4
|
107
112
|
summary: Capistrano extension to run mysqldump remotely, download, and import into
|
108
113
|
your local Rails development database
|
109
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- test/helper.rb
|
116
|
+
- test/test_capistrano-mysqldump.rb
|