capistrano3-postgres 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -8
- data/lib/capistrano3/postgres/version.rb +1 -1
- data/lib/capistrano3/tasks/postgres.rb +22 -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: 087895a85fd5bcae1fd8aa7ce96a921fc7f738e5
|
|
4
|
+
data.tar.gz: 9a919e94bea2d1b286949a0b435742b05c686041
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4b852cbfd8e8eadbd784fb1eaab73a9908ea3fcf7cf94689e490f8ae85dfd5af229388fe25c2d4717fe16ea00a95be2f7ee083abd30f58ec2e0370fc82f33a4
|
|
7
|
+
data.tar.gz: b932647d0ed037a1b21c2bffeeb4720d05fde1e596acb908ce006008126f58675db5efd716e12c473bd61f897db862eb519e07ce04b0eb295dc2ef7b30fb98fd
|
data/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
Add this line to your application's Gemfile:
|
|
6
6
|
|
|
7
|
-
gem 'capistrano3-postgres'
|
|
7
|
+
gem 'capistrano3-postgres', require: false
|
|
8
8
|
|
|
9
9
|
or:
|
|
10
10
|
|
|
11
|
-
gem 'capistrano3-postgres' , group: :development
|
|
11
|
+
gem 'capistrano3-postgres', require: false, group: :development
|
|
12
12
|
|
|
13
13
|
And then execute:
|
|
14
14
|
|
|
@@ -43,6 +43,10 @@ Sometimes it's a good idea to create dump before each deploy.
|
|
|
43
43
|
before 'deploy:starting', 'postgres:backup:create'
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
All downloaded dump files will be deleted after importing. If you want to keep them, you can set:
|
|
47
|
+
```
|
|
48
|
+
set :postgres_keep_local_dumps, 5 # Will keep 5 last dump files.
|
|
49
|
+
```
|
|
46
50
|
|
|
47
51
|
## Contributing
|
|
48
52
|
|
|
@@ -51,9 +55,3 @@ before 'deploy:starting', 'postgres:backup:create'
|
|
|
51
55
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
52
56
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
53
57
|
5. Create new Pull Request
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
@@ -3,6 +3,7 @@ namespace :load do
|
|
|
3
3
|
set :postgres_backup_dir, -> { 'postgres_backup' }
|
|
4
4
|
set :postgres_role, :db
|
|
5
5
|
set :postgres_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
|
|
6
|
+
set :postgres_keep_local_dumps, 0
|
|
6
7
|
set :postgres_remote_sqlc_file_path, -> { nil }
|
|
7
8
|
set :postgres_local_database_config, -> { nil }
|
|
8
9
|
set :postgres_remote_database_config, -> { nil }
|
|
@@ -24,7 +25,7 @@ namespace :postgres do
|
|
|
24
25
|
set :postgres_remote_sqlc_file_path, "#{shared_path}/#{fetch(:postgres_backup_dir)}/#{file_name}"
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
execute "PGPASSWORD=#{config['password']} pg_dump -U #{config['
|
|
28
|
+
execute "PGPASSWORD=#{config['password']} pg_dump -U #{config['username'] || config['user']} -h #{config['host']} -Fc --file=#{fetch(:postgres_remote_sqlc_file_path)} #{config['database']}"
|
|
28
29
|
end
|
|
29
30
|
end
|
|
30
31
|
|
|
@@ -37,6 +38,13 @@ namespace :postgres do
|
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
download!(fetch(:postgres_remote_sqlc_file_path), "tmp/#{fetch :postgres_backup_dir}/#{Pathname.new(fetch(:postgres_remote_sqlc_file_path)).basename}")
|
|
41
|
+
begin
|
|
42
|
+
remote_file = fetch(:postgres_remote_sqlc_file_path)
|
|
43
|
+
rescue SSHKit::Command::Failed => e
|
|
44
|
+
warn e.inspect
|
|
45
|
+
ensure
|
|
46
|
+
execute "rm #{remote_file}"
|
|
47
|
+
end
|
|
40
48
|
end
|
|
41
49
|
end
|
|
42
50
|
|
|
@@ -55,13 +63,14 @@ namespace :postgres do
|
|
|
55
63
|
file_path = "tmp/#{fetch :postgres_backup_dir}/#{file_name}"
|
|
56
64
|
begin
|
|
57
65
|
pgpass_path = File.join(Dir.pwd, '.pgpass')
|
|
58
|
-
File.open(pgpass_path, 'w+', 0600) { |file| file.write("*:*:*:#{config['
|
|
59
|
-
execute "PGPASSFILE=#{pgpass_path} pg_restore -c -U #{config['
|
|
66
|
+
File.open(pgpass_path, 'w+', 0600) { |file| file.write("*:*:*:#{config['username'] || config['user']}:#{config['password']}") }
|
|
67
|
+
execute "PGPASSFILE=#{pgpass_path} pg_restore -c -U #{config['username'] || config['user']} --no-owner -h #{config['host']} -p #{config['port'] || 5432 } -d #{fetch(:database_name)} #{file_path}"
|
|
60
68
|
rescue SSHKit::Command::Failed => e
|
|
61
69
|
warn e.inspect
|
|
62
70
|
info 'Import performed successfully!'
|
|
63
71
|
ensure
|
|
64
72
|
File.delete(pgpass_path) if File.exist?(pgpass_path)
|
|
73
|
+
File.delete(file_path) if (fetch(:postgres_keep_local_dumps) == 0) && File.exist?(file_path)
|
|
65
74
|
end
|
|
66
75
|
end
|
|
67
76
|
end
|
|
@@ -82,6 +91,15 @@ namespace :postgres do
|
|
|
82
91
|
end
|
|
83
92
|
end
|
|
84
93
|
end
|
|
94
|
+
|
|
95
|
+
desc "Cleanup old local dumps"
|
|
96
|
+
task :cleanup do
|
|
97
|
+
run_locally do
|
|
98
|
+
dir = "tmp/#{fetch :postgres_backup_dir}"
|
|
99
|
+
file_names = capture("ls -v #{dir}").split(/\n/).sort
|
|
100
|
+
file_names[0...-fetch(:postgres_keep_local_dumps)].each {|file_name| File.delete("#{dir}/#{file_name}") }
|
|
101
|
+
end
|
|
102
|
+
end
|
|
85
103
|
end
|
|
86
104
|
|
|
87
105
|
desc 'Replecate database locally'
|
|
@@ -92,6 +110,7 @@ namespace :postgres do
|
|
|
92
110
|
invoke "postgres:backup:create"
|
|
93
111
|
invoke "postgres:backup:download"
|
|
94
112
|
invoke "postgres:backup:import"
|
|
113
|
+
invoke("postgres:backup:cleanup") if fetch(:postgres_keep_local_dumps) > 0
|
|
95
114
|
end
|
|
96
115
|
|
|
97
116
|
# Grabs local database config before importing dump
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano3-postgres
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Krasynskyi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: capistrano
|