capistrano-db_sync 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/capistrano-db_sync.gemspec +2 -2
- data/lib/capistrano/db_sync/configuration.rb +4 -2
- data/lib/capistrano/db_sync/postgres/cli.rb +12 -8
- data/lib/capistrano/db_sync/version.rb +1 -1
- data/spec/lib/capistrano/db_sync/postgres/cli_spec.rb +92 -21
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ef45f2b85cc220b6ffeacdf2aa5d73999798973
|
4
|
+
data.tar.gz: 94bd2de62b244170fa0d1890d54b0dfc6584d902
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8593d8accbb23f835447f3f317ffc20da35d46f25d0c2a08f8cd6916ca8ab20172ded4dd34580693edd84bba62b8c08222ecef20b0a4a7ce9dc392c3b887372
|
7
|
+
data.tar.gz: 9e75118beffc54c8d195e4d5fe315fa074ff304f95e2d506ad8254cc22c55c382128a65f8640f700413e15e4d2c9c6c08f1edeee529ef1f9d823d89179b08ad3
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
[![Build Status](https://snap-ci.com/heartbits/capistrano-db_sync/branch/master/build_image)](https://snap-ci.com/heartbits/capistrano-db_sync/branch/master)
|
2
|
-
|
3
|
-
## Capistrano::DBSync
|
1
|
+
### Capistrano::DBSync [![Build Status](https://snap-ci.com/heartbits/capistrano-db_sync/branch/master/build_image)](https://snap-ci.com/heartbits/capistrano-db_sync/branch/master) [![Code Climate](https://codeclimate.com/github/heartbits/capistrano-db_sync/badges/gpa.svg)](https://codeclimate.com/github/heartbits/capistrano-db_sync)
|
4
2
|
|
5
3
|
Fast and sophisticated remote database import using the best of **Postgres 9.2.x**
|
6
4
|
|
@@ -10,6 +8,7 @@ Fast and sophisticated remote database import using the best of **Postgres 9.2.x
|
|
10
8
|
* No downtime on restore - it uses a temporary database while restoring
|
11
9
|
* Uses Postgres parallel restore
|
12
10
|
* Uses Postgres custom dump format that is automatically compressed
|
11
|
+
* *MySQL will be supported in near future*
|
13
12
|
|
14
13
|
### Requirements
|
15
14
|
|
@@ -25,6 +24,7 @@ Fast and sophisticated remote database import using the best of **Postgres 9.2.x
|
|
25
24
|
```ruby
|
26
25
|
gem 'capistrano-db_sync', require: false
|
27
26
|
```
|
27
|
+
Available in RubyGems: https://rubygems.org/gems/capistrano-db_sync
|
28
28
|
|
29
29
|
2. Define your custom settings, if needed. We suggest to put this file at `lib/capistrano/tasks/db_sync.rake`.
|
30
30
|
Capistrano 3.x should load all `*.rake` files by default in `Capfile`.
|
@@ -78,11 +78,18 @@ The following steps describe what happens when executing `cap production db_sync
|
|
78
78
|
|
79
79
|
### Contributors
|
80
80
|
|
81
|
-
* Rafael Sales [@rafaelsales](
|
81
|
+
* Rafael Sales [@rafaelsales](https://github.com/rafaelsales)
|
82
|
+
* Jérémy Lecour [@jlecour](https://github.com/jlecour)
|
83
|
+
|
84
|
+
### Plans
|
85
|
+
|
86
|
+
* Increase test coverage
|
87
|
+
* Add support to MySQL
|
88
|
+
* Validate database versions before applying any changes
|
82
89
|
|
83
90
|
### Contributing
|
84
91
|
|
85
|
-
1. Fork it ( https://github.com/
|
92
|
+
1. Fork it ( https://github.com/heartbits/capistrano-db_sync/fork )
|
86
93
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
94
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
95
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/capistrano-db_sync.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "capistrano", ">= 3.0.0"
|
22
|
-
spec.add_dependency "activesupport", ">= 3.0.0"
|
21
|
+
spec.add_runtime_dependency "capistrano", "~> 3.0.0", ">= 3.0.0"
|
22
|
+
spec.add_dependency "activesupport", "~> 3.0.0", ">= 3.0.0"
|
23
23
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'tmpdir'
|
1
2
|
require 'active_support/core_ext/hash'
|
2
3
|
|
3
4
|
module Capistrano::DBSync
|
@@ -21,14 +22,14 @@ module Capistrano::DBSync
|
|
21
22
|
|
22
23
|
pg_jobs: 1, # Number of jobs to run in parallel on pg_restore
|
23
24
|
|
24
|
-
working_dir:
|
25
|
+
working_dir: Dir.tmpdir,
|
25
26
|
env: ENV.fetch('RAILS_ENV', 'development'),
|
26
27
|
},
|
27
28
|
|
28
29
|
remote: {
|
29
30
|
cleanup: true, # If the remote dump directory should be removed after downloaded
|
30
31
|
|
31
|
-
working_dir: "/tmp",
|
32
|
+
working_dir: cap.fetch(:tmp_dir, "/tmp"),
|
32
33
|
env: cap.fetch(:stage).to_s,
|
33
34
|
},
|
34
35
|
}
|
@@ -41,6 +42,7 @@ module Capistrano::DBSync
|
|
41
42
|
|
42
43
|
def load_options
|
43
44
|
user_options = cap.fetch(:db_sync_options)
|
45
|
+
user_options = user_options.reject { |_, v| v.nil? }
|
44
46
|
DEFAULT_OPTIONS.call(cap).deep_merge(user_options)
|
45
47
|
end
|
46
48
|
|
@@ -4,11 +4,13 @@ class Capistrano::DBSync::Postgres::CLI
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def dump(to_file, db, options = [])
|
7
|
-
|
7
|
+
args = to_string_args(options)
|
8
|
+
"#{with_pw} pg_dump #{credentials} #{format_args} -f #{to_file} #{args} #{db}".strip
|
8
9
|
end
|
9
10
|
|
10
11
|
def restore(from_file, db, options = [])
|
11
|
-
|
12
|
+
args = to_string_args(options)
|
13
|
+
"#{with_pw} pg_restore #{credentials} #{format_args} -d #{db} #{args} #{from_file}".strip
|
12
14
|
end
|
13
15
|
|
14
16
|
def drop_db(db)
|
@@ -23,13 +25,9 @@ class Capistrano::DBSync::Postgres::CLI
|
|
23
25
|
psql %Q|ALTER DATABASE "#{old_db}" RENAME TO "#{new_db}";|
|
24
26
|
end
|
25
27
|
|
26
|
-
def clone_db(new_db, template_db)
|
27
|
-
psql %Q|CREATE DATABASE "#{new_db}" WITH TEMPLATE "#{template_db}";|
|
28
|
-
end
|
29
|
-
|
30
28
|
def psql(command, db = "postgres")
|
31
29
|
normalized_command = command.gsub('"', '\"').gsub(/\s\s+|\n/, " ")
|
32
|
-
%Q|#{with_pw} psql #{credentials} -d #{db} -c "#{normalized_command}"
|
30
|
+
%Q|#{with_pw} psql #{credentials} -d #{db} -c "#{normalized_command}"|.strip
|
33
31
|
end
|
34
32
|
|
35
33
|
def kill_processes_for_db(db)
|
@@ -64,7 +62,13 @@ class Capistrano::DBSync::Postgres::CLI
|
|
64
62
|
end
|
65
63
|
|
66
64
|
def with_pw
|
67
|
-
|
65
|
+
if config['password']
|
66
|
+
"PGPASSWORD='#{config['password']}'"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_string_args(options)
|
71
|
+
options.nil? ? "" : options.join(" ")
|
68
72
|
end
|
69
73
|
|
70
74
|
attr_reader :config, :session_id
|
@@ -1,30 +1,101 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
describe "Using a config with a password" do
|
4
|
+
|
5
|
+
describe Capistrano::DBSync::Postgres::CLI do
|
6
|
+
let(:config) do
|
7
|
+
{
|
8
|
+
"database" => "staging",
|
9
|
+
"username" => "user",
|
10
|
+
"password" => "pw",
|
11
|
+
"adapter" => "postgresql",
|
12
|
+
"host" => "127.0.0.1",
|
13
|
+
"port" => "5432",
|
14
|
+
}
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
let(:cli) { Capistrano::DBSync::Postgres::CLI.new(config) }
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
describe "#dump" do
|
20
|
+
it "generates pg_dump command" do
|
21
|
+
command = cli.dump("/tmp/staging.dump", "staging", ["--section=pre-data"])
|
22
|
+
command.must_equal "PGPASSWORD='pw' pg_dump -U user -h 127.0.0.1 -p 5432 --no-acl --no-owner --format=custom -f /tmp/staging.dump --section=pre-data staging"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#restore" do
|
27
|
+
it "generates pg_dump command" do
|
28
|
+
command = cli.restore("/db/production.dump", "staging", ["--jobs=3"])
|
29
|
+
command.must_equal "PGPASSWORD='pw' pg_restore -U user -h 127.0.0.1 -p 5432 --no-acl --no-owner --format=custom -d staging --jobs=3 /db/production.dump"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#psql" do
|
34
|
+
it "generates a command to drop a database" do
|
35
|
+
command = cli.psql("fake command")
|
36
|
+
command.must_equal %Q{PGPASSWORD='pw' psql -U user -h 127.0.0.1 -p 5432 -d postgres -c "fake command"}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#drop_db" do
|
41
|
+
it "generates a command to drop a database" do
|
42
|
+
command = cli.drop_db("staging")
|
43
|
+
command.must_match /psql .* -c "DROP DATABASE IF EXISTS \\"staging\\";"/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#create_db" do
|
48
|
+
it "generates a database creation command" do
|
49
|
+
command = cli.create_db("staging")
|
50
|
+
command.must_match /psql .* -c "CREATE DATABASE \\"staging\\";"/
|
51
|
+
end
|
21
52
|
end
|
22
|
-
end
|
23
53
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
54
|
+
describe "#rename_db" do
|
55
|
+
it "generates a database creation command" do
|
56
|
+
command = cli.rename_db("staging_old", "staging_new")
|
57
|
+
command.must_match /psql .* -c "ALTER DATABASE \\"staging_old\\" RENAME TO \\"staging_new\\";"/
|
58
|
+
end
|
28
59
|
end
|
29
60
|
end
|
30
61
|
end
|
62
|
+
|
63
|
+
describe "Using a config without password" do
|
64
|
+
|
65
|
+
describe Capistrano::DBSync::Postgres::CLI do
|
66
|
+
let(:config) do
|
67
|
+
{
|
68
|
+
"database" => "staging",
|
69
|
+
"username" => "user",
|
70
|
+
"adapter" => "postgresql",
|
71
|
+
"host" => "127.0.0.1",
|
72
|
+
"port" => "5432",
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:cli) { Capistrano::DBSync::Postgres::CLI.new(config) }
|
77
|
+
|
78
|
+
describe "#dump" do
|
79
|
+
it "generates pg_dump command" do
|
80
|
+
command = cli.dump("/tmp/staging.dump", "staging", ["--section=pre-data"])
|
81
|
+
command.must_equal "pg_dump -U user -h 127.0.0.1 -p 5432 --no-acl --no-owner --format=custom -f /tmp/staging.dump --section=pre-data staging"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#restore" do
|
86
|
+
it "generates pg_dump command" do
|
87
|
+
command = cli.restore("/db/production.dump", "staging", ["--jobs=3"])
|
88
|
+
command.must_equal "pg_restore -U user -h 127.0.0.1 -p 5432 --no-acl --no-owner --format=custom -d staging --jobs=3 /db/production.dump"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#psql" do
|
93
|
+
it "generates a command to drop a database" do
|
94
|
+
command = cli.psql("fake command")
|
95
|
+
command.must_equal %Q{psql -U user -h 127.0.0.1 -p 5432 -d postgres -c "fake command"}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-db_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Sales
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 3.0.0
|
@@ -21,6 +24,9 @@ dependencies:
|
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 3.0.0
|
@@ -28,6 +34,9 @@ dependencies:
|
|
28
34
|
name: activesupport
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.0.0
|
31
40
|
- - ">="
|
32
41
|
- !ruby/object:Gem::Version
|
33
42
|
version: 3.0.0
|
@@ -35,6 +44,9 @@ dependencies:
|
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.0.0
|
38
50
|
- - ">="
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: 3.0.0
|