capistrano-postgresql 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ac96a8782805305ec27d12b90dee2777b48c081
4
- data.tar.gz: 4c575b7874fd8c42cd7de70e177af3e9d495fffc
3
+ metadata.gz: 64756f3cbd959704ddb49e120d669ce593817398
4
+ data.tar.gz: 476e3f52826affad3fbcba2beb04db05a0a30593
5
5
  SHA512:
6
- metadata.gz: 4b9f7b18da40c71f8c4b9a06bf9703bbfeb36722655e91d42d76fb58921f752f1b93b430baa84c74e8a61ee4468b8b2af31ee82f3b1aab5409d872f38348aaf4
7
- data.tar.gz: c700d02f33eb191950d2f38046ffe43c8df0dd6dc6643569fad2c2c1deaaf4b6640ac7e95374d74e6eb9df7504a0903ea94efcfe8cb8c14b2c1b01884482ee2d
6
+ metadata.gz: 43b02bb91ec6bfa9d8ed3cd59408961bf5a81f8556e02718937c5c86796411c07731a00ae509820a1a14b7c75fcfb9448034d907b2b7a58575d8c50da773ec0c
7
+ data.tar.gz: e6d8cb4b11369573d62faf246a4ec479c8eb78e4b7ac7e395df238b4f74d82a76fdcc20650b785fd54fea1f463c637472126a745c4e076d81954acf56d5d0f81
@@ -0,0 +1,82 @@
1
+ require 'securerandom'
2
+ require 'erb'
3
+
4
+ module Capistrano
5
+ module Postgresql
6
+ module HelperMethods
7
+
8
+ def database_yml_template(template_name, target)
9
+ config_file = "#{fetch(:postgresql_templates_path)}/#{template_name}"
10
+ # If there's no customized file in your rails app template directory,
11
+ # proceed with the default.
12
+ unless File.exists?(config_file)
13
+ config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/postgresql/templates/#{template_name}")
14
+ end
15
+ upload! StringIO.new(ERB.new(File.read(config_file)).result(binding)), target
16
+ end
17
+
18
+ # This method is invoked only if `:postgresql_password` is not already set in
19
+ # `config/deploy.rb`. Directly setting `:postgresql_password` has precedence.
20
+ def ask_for_or_generate_password
21
+ if fetch(:postgresql_ask_for_password)
22
+ ask :postgresql_password, "Postgresql database password for the app: "
23
+ else
24
+ set :postgresql_password, generate_random_password
25
+ end
26
+ end
27
+
28
+ def generate_random_password
29
+ SecureRandom.hex(10)
30
+ end
31
+
32
+ def db_user_exists?(name)
33
+ psql "-tAc", %Q{"SELECT 1 FROM pg_roles WHERE rolname='#{name}';" | grep -q 1}
34
+ end
35
+
36
+ def create_db_user(name, password)
37
+ if psql "-c", %Q{"CREATE user #{name} WITH password '#{password}';"}
38
+ info "postgresq: database user '#{name}' created"
39
+ else
40
+ error "postgresql: creating database user failed!"
41
+ exit 1
42
+ end
43
+ end
44
+
45
+ def ensure_db_user_created(name, password)
46
+ unless db_user_exists?(name)
47
+ create_db_user(name, password)
48
+ end
49
+ end
50
+
51
+ def database_exists?(db_name)
52
+ psql "-tAc", %Q{"SELECT 1 FROM pg_database WHERE datname='#{db_name}';" | grep -q 1}
53
+ end
54
+
55
+ def create_database(db_name, user_name)
56
+ if psql "-c", %Q{"CREATE database #{db_name} owner #{user_name};"}
57
+ info "postgresql: database '#{db_name}' created"
58
+ else
59
+ error "postgresql: creating database '#{db_name}' failed!"
60
+ exit 1
61
+ end
62
+ end
63
+
64
+ def ensure_database_created(db_name, user_name)
65
+ unless database_exists?(db_name)
66
+ create_database(db_name, user_name)
67
+ end
68
+ end
69
+
70
+ # returns true or false depending on the remote command exit status
71
+ def psql(*args)
72
+ test :sudo, "-u postgres psql", *args
73
+ end
74
+
75
+ def remote_file_exists?(path)
76
+ test "[ -e #{path} ]"
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Postgresql
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -1,76 +1,6 @@
1
- require 'securerandom'
2
- require 'erb'
1
+ require 'capistrano/postgresql/helper_methods'
3
2
 
4
- def database_yml_template(template_name, target)
5
- config_file = "#{fetch(:postgresql_templates_path)}/#{template_name}"
6
- # If there's no customized file in your rails app template directory,
7
- # proceed with the default.
8
- unless File.exists?(config_file)
9
- config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/postgresql/templates/#{template_name}")
10
- end
11
- upload! StringIO.new(ERB.new(File.read(config_file)).result(binding)), target
12
- end
13
-
14
- # This method is invoked only if `:postgresql_password` is not already set in
15
- # `config/deploy.rb`. Directly setting `:postgresql_password` has precedence.
16
- def ask_for_or_generate_password
17
- if fetch(:postgresql_ask_for_password)
18
- ask :postgresql_password, "Postgresql database password for the app: "
19
- else
20
- set :postgresql_password, generate_random_password
21
- end
22
- end
23
-
24
- def generate_random_password
25
- SecureRandom.hex(10)
26
- end
27
-
28
- def db_user_exists?(name)
29
- psql "-tAc", %Q{"SELECT 1 FROM pg_roles WHERE rolname='#{name}';" | grep -q 1}
30
- end
31
-
32
- def create_db_user(name, password)
33
- if psql "-c", %Q{"CREATE user #{name} WITH password '#{password}';"}
34
- info "postgresq: database user '#{name}' created"
35
- else
36
- error "postgresql: creating database user failed!"
37
- exit 1
38
- end
39
- end
40
-
41
- def ensure_db_user_created(name, password)
42
- unless db_user_exists?(name)
43
- create_db_user(name, password)
44
- end
45
- end
46
-
47
- def database_exists?(db_name)
48
- psql "-tAc", %Q{"SELECT 1 FROM pg_database WHERE datname='#{db_name}';" | grep -q 1}
49
- end
50
-
51
- def create_database(db_name, user_name)
52
- if psql "-c", %Q{"CREATE database #{db_name} owner #{user_name};"}
53
- info "postgresql: database '#{db_name}' created"
54
- else
55
- error "postgresql: creating database '#{db_name}' failed!"
56
- exit 1
57
- end
58
- end
59
-
60
- def ensure_database_created(db_name, user_name)
61
- unless database_exists?(db_name)
62
- create_database(db_name, user_name)
63
- end
64
- end
65
-
66
- # returns true or false depending on the remote command exit status
67
- def psql(*args)
68
- test :sudo, "-u postgres psql", *args
69
- end
70
-
71
- def remote_file_exists?(path)
72
- test "[ -e #{path} ]"
73
- end
3
+ include Capistrano::Postgresql::HelperMethods
74
4
 
75
5
  namespace :load do
76
6
  task :defaults do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Sutic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -56,6 +56,7 @@ files:
56
56
  - capistrano-postgresql.gemspec
57
57
  - lib/capistrano-postgresql.rb
58
58
  - lib/capistrano/postgresql.rb
59
+ - lib/capistrano/postgresql/helper_methods.rb
59
60
  - lib/capistrano/postgresql/version.rb
60
61
  - lib/capistrano/tasks/postgresql.rake
61
62
  - lib/generators/capistrano/postgresql/README.md