capistrano3-postgres 0.1.0 → 0.1.1

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: 087895a85fd5bcae1fd8aa7ce96a921fc7f738e5
4
- data.tar.gz: 9a919e94bea2d1b286949a0b435742b05c686041
3
+ metadata.gz: 5cadbc1ab83d70005145bf3b402d00603b09ec44
4
+ data.tar.gz: e93cb5ec0d64c3a76ce6d0f62ac8651f0275e85b
5
5
  SHA512:
6
- metadata.gz: f4b852cbfd8e8eadbd784fb1eaab73a9908ea3fcf7cf94689e490f8ae85dfd5af229388fe25c2d4717fe16ea00a95be2f7ee083abd30f58ec2e0370fc82f33a4
7
- data.tar.gz: b932647d0ed037a1b21c2bffeeb4720d05fde1e596acb908ce006008126f58675db5efd716e12c473bd61f897db862eb519e07ce04b0eb295dc2ef7b30fb98fd
6
+ metadata.gz: 1d68b4d312738cb1c84e1789b4f7c267f744434789714eebb93324ee5660d469a42eac0ed462743186b8c1060f1ff75e4c5aea7d499345ee4bd04121ac2ed159
7
+ data.tar.gz: f0a7127c3de88976231a06800a0c61f73608cdecf1ba421648553dbf6b13aab680036d06675148a13a6957b68ab2e3e3c95662a8b7901985e91c792fe70ff004
@@ -1,5 +1,5 @@
1
1
  module Capistrano3
2
2
  module Postgres
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -25,7 +25,7 @@ namespace :postgres do
25
25
  set :postgres_remote_sqlc_file_path, "#{shared_path}/#{fetch(:postgres_backup_dir)}/#{file_name}"
26
26
  end
27
27
 
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
+ execute "PGPASSWORD=#{config['password']} pg_dump #{user_option(config)} -h #{config['host']} -Fc --file=#{fetch(:postgres_remote_sqlc_file_path)} #{config['database']}"
29
29
  end
30
30
  end
31
31
 
@@ -64,7 +64,7 @@ namespace :postgres do
64
64
  begin
65
65
  pgpass_path = File.join(Dir.pwd, '.pgpass')
66
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}"
67
+ execute "PGPASSFILE=#{pgpass_path} pg_restore -c #{user_option(config)} --no-owner -h #{config['host']} -p #{config['port'] || 5432 } -d #{fetch(:database_name)} #{file_path}"
68
68
  rescue SSHKit::Command::Failed => e
69
69
  warn e.inspect
70
70
  info 'Import performed successfully!'
@@ -102,7 +102,7 @@ namespace :postgres do
102
102
  end
103
103
  end
104
104
 
105
- desc 'Replecate database locally'
105
+ desc 'Replicate database locally'
106
106
  task :replicate do
107
107
  grab_local_database_config
108
108
  config = fetch(:postgres_local_database_config)
@@ -113,13 +113,21 @@ namespace :postgres do
113
113
  invoke("postgres:backup:cleanup") if fetch(:postgres_keep_local_dumps) > 0
114
114
  end
115
115
 
116
+ def user_option(config)
117
+ if config['user'] || config['username']
118
+ "-U #{config['user'] || config['username']}"
119
+ else
120
+ '' # assume ident auth is being used
121
+ end
122
+ end
123
+
116
124
  # Grabs local database config before importing dump
117
125
  def grab_local_database_config
118
126
  return if fetch(:postgres_local_database_config)
119
127
  on roles(fetch(:postgres_role)) do |role|
120
128
  run_locally do
121
129
  env = 'development'
122
- yaml_content = capture "cat config/database.yml"
130
+ yaml_content = ERB.new(capture "cat config/database.yml").result
123
131
  set :postgres_local_database_config, database_config_defaults.merge(YAML::load(yaml_content)[env])
124
132
  end
125
133
  end
@@ -130,13 +138,14 @@ namespace :postgres do
130
138
  return if fetch(:postgres_remote_database_config)
131
139
  on roles(fetch(:postgres_role)) do |role|
132
140
  env = fetch(:postgres_env).to_s.downcase
133
- yaml_content = capture "cat #{deploy_to}/current/config/database.yml"
141
+ filename = "#{deploy_to}/current/config/database.yml"
142
+ yaml_content = capture "ruby -e \"require 'erb'; puts ERB.new(File.read('#{filename}')).result\""
134
143
  set :postgres_remote_database_config, database_config_defaults.merge(YAML::load(yaml_content)[env])
135
144
  end
136
145
  end
137
146
 
138
147
  def database_config_defaults
139
- { 'host' => 'localhost', 'user' => 'postgres' }
148
+ { 'host' => 'localhost' }
140
149
  end
141
150
 
142
151
  end
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.1.0
4
+ version: 0.1.1
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-09-03 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano