capistrano3-postgres 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7a08e03347397dea2b027afa75fac9929f82184
4
- data.tar.gz: 7c3b1d8765ea24754701b0e31951d4f30a7531cd
3
+ metadata.gz: 087895a85fd5bcae1fd8aa7ce96a921fc7f738e5
4
+ data.tar.gz: 9a919e94bea2d1b286949a0b435742b05c686041
5
5
  SHA512:
6
- metadata.gz: 8527c0f1c0a9a97195909d7c095a267c0508a43bca5615098d1c3aa238e3c518feb9692e7771d6d103bf522b9e80260fe91f1bac26b3ed16b26f58e1c7611e66
7
- data.tar.gz: 703183c9f4a37a4632aa9e960988cd110a13a515b4dd8929f9a837080a7e24bd09a3b806620ccfac47f67de60db14b7b49a72bd67ca053feacd5729e62db6de0
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
-
@@ -1,5 +1,5 @@
1
1
  module Capistrano3
2
2
  module Postgres
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -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['user'] || config['username']} -h #{config['host']} -Fc --file=#{fetch(:postgres_remote_sqlc_file_path)} #{config['database']}"
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['user'] || config['username']}:#{config['password']}") }
59
- execute "PGPASSFILE=#{pgpass_path} pg_restore -c -U #{config['user'] || config['username']} --no-owner -h #{config['host']} -d #{fetch(:database_name)} #{file_path}"
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.3
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-06-03 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano