capistrano-db_sync 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/capistrano/db_sync/postgres/cli.rb +4 -4
- data/lib/capistrano/db_sync/postgres/exporter.rb +1 -1
- data/lib/capistrano/db_sync/postgres/importer.rb +1 -1
- data/lib/capistrano/db_sync/version.rb +1 -1
- data/spec/lib/capistrano/db_sync/postgres/exporter_spec.rb +8 -8
- data/spec/lib/capistrano/db_sync/postgres/importer_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ac7a777e216b28b76c7d74495c2ac24ac043d7a
|
4
|
+
data.tar.gz: 7f6dce31e24ddf589319d52f4b1a92f4d3830386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4cfb9da1b149eed3247badcde9fdde382b6204063cb284acb011fbdbc592a2343933e92e218c4c795fa80c8b3db1e9512882695ffca70f4104a9e13b6a9d24c
|
7
|
+
data.tar.gz: 809713ff8d936873c98aab1bec2b8046f19e353f3e21bc89f12a0d39892391c6633fcd89d515666d0187d041cf3e4b25196b697b71f0acc5e5e56ec2eaa831a1
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
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
|
+
|
1
3
|
## Capistrano::DBSync
|
2
4
|
|
3
5
|
Fast and sophisticated remote database import using the best of **Postgres 9.2.x**
|
4
6
|
|
5
7
|
### Features
|
6
8
|
|
7
|
-
* Allows
|
9
|
+
* Allows dumping data selectively - choose between entire, partial or no data
|
10
|
+
* No downtime on restore - it uses a temporary database while restoring
|
8
11
|
* Uses Postgres parallel restore
|
9
12
|
* Uses Postgres custom dump format that is automatically compressed
|
10
13
|
|
@@ -20,10 +23,10 @@ Fast and sophisticated remote database import using the best of **Postgres 9.2.x
|
|
20
23
|
1. Add this line to your application's Gemfile:
|
21
24
|
|
22
25
|
```ruby
|
23
|
-
gem 'capistrano-
|
26
|
+
gem 'capistrano-db_sync', require: false
|
24
27
|
```
|
25
28
|
|
26
|
-
2. Define your custom settings, if needed. We suggest to
|
29
|
+
2. Define your custom settings, if needed. We suggest to put this file at `lib/capistrano/tasks/db_sync.rake`.
|
27
30
|
Capistrano 3.x should load all `*.rake` files by default in `Capfile`.
|
28
31
|
[See the complete configuration reference](/lib/capistrano/db_sync/configuration.rb)
|
29
32
|
|
@@ -73,6 +76,9 @@ The following steps describe what happens when executing `cap production db_sync
|
|
73
76
|
3. data for tables with partial data specified in configuration
|
74
77
|
4. triggers, constraints, rules and indexes
|
75
78
|
|
79
|
+
### Contributors
|
80
|
+
|
81
|
+
* Rafael Sales [@rafaelsales](http://github.com/rafaelsales) - help me not stay forever alone here :)
|
76
82
|
|
77
83
|
### Contributing
|
78
84
|
|
@@ -41,12 +41,12 @@ class Capistrano::DBSync::Postgres::CLI
|
|
41
41
|
SQL
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
45
|
-
psql "\\
|
44
|
+
def copy_and_compress_to_file(to_compressed_file, db, query)
|
45
|
+
psql "\\copy (#{query}) TO PROGRAM 'gzip > #{to_compressed_file}' WITH CSV", db
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
psql "\\
|
48
|
+
def copy_from_compressed_file(from_compressed_file, db, table)
|
49
|
+
psql "\\copy #{table} FROM PROGRAM 'gunzip --to-stdout #{from_compressed_file}' WITH CSV", db
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
@@ -52,7 +52,7 @@ module Capistrano::DBSync
|
|
52
52
|
|
53
53
|
def dump_partial_selected_data(db, file_namer, data_selection)
|
54
54
|
data_selection.map do |table, query|
|
55
|
-
cli.
|
55
|
+
cli.copy_and_compress_to_file(file_namer.next(table, :table), db, query) if query
|
56
56
|
end.compact
|
57
57
|
end
|
58
58
|
|
@@ -70,7 +70,7 @@ module Capistrano::DBSync
|
|
70
70
|
files = Dir.glob(File.join(working_dir, "*.table"))
|
71
71
|
files.map do |file|
|
72
72
|
table_name = Postgres::FileNameGenerator.extract_name(file)
|
73
|
-
cli.
|
73
|
+
cli.copy_from_compressed_file(file, to_db, table_name)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -8,9 +8,9 @@ describe Capistrano::DBSync::Postgres::Exporter do
|
|
8
8
|
describe "#dump" do
|
9
9
|
let(:data_selection) do
|
10
10
|
{
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
posts: "SELECT * FROM posts WHERE date > NOW() - interval '160 days'",
|
12
|
+
comments: "SELECT * FROM comments WHERE created_at > NOW() - interval '160 days'",
|
13
|
+
likes: nil
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
@@ -19,13 +19,13 @@ describe Capistrano::DBSync::Postgres::Exporter do
|
|
19
19
|
|
20
20
|
# Assert dumping database schema with data except for tables specified on data_selection
|
21
21
|
commands[0].must_match /pg_dump.* -f \/tmp\/dumps\/0001-faceburger_production\.schema/
|
22
|
-
commands[0].must_match /--exclude-table-data="
|
23
|
-
commands[0].must_match /--exclude-table-data="
|
24
|
-
commands[0].must_match /--exclude-table-data="
|
22
|
+
commands[0].must_match /--exclude-table-data="posts"/
|
23
|
+
commands[0].must_match /--exclude-table-data="comments"/
|
24
|
+
commands[0].must_match /--exclude-table-data="likes"/
|
25
25
|
|
26
26
|
# Assert dumping data for tables specified on data_selection
|
27
|
-
commands[1].must_match /
|
28
|
-
commands[2].must_match /
|
27
|
+
commands[1].must_match /copy.*posts.*\/tmp\/dumps\/0002-posts\.table/
|
28
|
+
commands[2].must_match /copy.*comments.*\/tmp\/dumps\/0003-comments\.table/
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -11,7 +11,7 @@ describe Capistrano::DBSync::Postgres::Importer do
|
|
11
11
|
.returns(["/tmp/dumps/0001-faceburger_production.schema"])
|
12
12
|
|
13
13
|
Dir.stubs(:glob).with("/tmp/dumps/*.table")
|
14
|
-
.returns(["/tmp/dumps/0002-
|
14
|
+
.returns(["/tmp/dumps/0002-posts.table", "/tmp/dumps/0003-comments.table"])
|
15
15
|
end
|
16
16
|
|
17
17
|
it "restore dump files" do
|
@@ -27,8 +27,8 @@ describe Capistrano::DBSync::Postgres::Importer do
|
|
27
27
|
commands[3].must_match /pg_restore.* \/tmp\/dumps\/0001-faceburger_production\.schema/
|
28
28
|
|
29
29
|
# Assert import selective tables data
|
30
|
-
commands[4].must_match /
|
31
|
-
commands[5].must_match /
|
30
|
+
commands[4].must_match /copy posts.*\/tmp\/dumps\/0002-posts\.table/
|
31
|
+
commands[5].must_match /copy comments.*\/tmp\/dumps\/0003-comments\.table/
|
32
32
|
|
33
33
|
# Assert restore indexes, constraints, triggers and rules
|
34
34
|
commands[6].must_match /pg_restore.*--section=post-data --jobs=3/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|