You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Fix for pg_without_sudo; Wasn't adding -U to args
- New feature that will ALTER USER/Password with any change to pg_password. Random passwords will cause each cap setup to run the ALTER USER, but that's fine as a user should technically only be using setup initially. It's not that hard to obtain the new password if this happens.
- New redaction for logging of passwords & SSHKIT 1.17.0 in gemspec
- README updates
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,12 @@
2
2
3
3
### master
4
4
5
+
## v6.0.0, 2018-07-09
6
+
- Fix for pg_without_sudo; Wasn't adding -U to args
7
+
- New feature that will ALTER USER/Password with any change to pg_password. Random passwords will cause each cap setup to run the ALTER USER, but that's fine as a user should technically only be using setup initially. It's not that hard to obtain the new password if this happens.
8
+
- New redaction for logging of passwords & SSHKIT 1.17.0 in gemspec
9
+
- README updates
10
+
5
11
## v5.0.1, 2018-06-05
6
12
- Quick fix for fetch(:pg_database) on extension adding
You need to include ONLY ONE of the following in your config/deploy/*.rb files:
46
46
47
47
```
48
-
set :pg_password, ENV['DATABASE_USER_PASSWORD']
49
-
set :pg_ask_for_password, true
50
-
set :pg_generate_random_password, true
48
+
set :pg_password, ENV['DATABASE_USER_PASSWORD'] # Example is an ENV value, but you can use a string instead
49
+
set :pg_ask_for_password, true # Prompts user for password on execution of setup
50
+
set :pg_generate_random_password, true # Generates a random password on each setup
51
51
```
52
52
53
+
##### Execution of `cap ENV setup` will run ALTER USER on pg_username if there is a different password. If you're using :pg_generate_random_password, you'll get a new random password on each run.
54
+
53
55
Example config:
54
56
55
57
```
56
-
server 'growtrader.dev', user: 'growtrader', roles: %w{app db}
58
+
server 'yoursite.net', user: 'growtrader', roles: %w{app db}
57
59
set :stage, :development
58
60
set :branch, 'development'
59
61
# ==================
60
62
# Postgresql setup
61
63
set :pg_without_sudo, false
62
-
set :pg_host, 'growtrader.dev'
63
-
set :pg_database, 'growtrader'
64
-
set :pg_username, 'growtrader'
64
+
set :pg_host, 'db.yoursite.net'
65
+
set :pg_database, 'pg_database_name_here'
66
+
set :pg_username, 'pg_username_here'
65
67
#set :pg_generate_random_password, true
66
68
#set :pg_ask_for_password, true
67
-
set :pg_password, ENV['GROWTRADER_PGPASS']
69
+
set :pg_password, ENV['yoursite_PGPASS']
68
70
set :pg_extensions, ['citext','hstore']
69
71
set :pg_encoding, 'UTF-8'
70
72
set :pg_pool, '100'
71
73
```
72
74
73
75
Finally, to setup the server(s), run:
74
76
75
-
$ bundle exec cap production setup
77
+
$ bundle exec cap development setup
76
78
77
79
### Requirements
78
-
79
80
* Be sure to remove `config/database.yml` from your application's version control.
80
-
* Your pg_hba.conf must include `local all all trust`
81
+
* Your pg_hba.conf must include `local all all trust`. We ssh into the servers to execute psql commands.
81
82
* Make sure the `deploy_to` path exists and has the right privileges on your servers. The ~ symbol (i.e. `~/myapp`) is not supported.
82
-
* Within your app/config/deploy/{env}.rb files, you need to specify at least one :app and one :db server.
83
+
* Within your app/config/deploy/{env}.rb files, you need to specify at least one :app and one :db server (they can be on the same host; `roles: %w{web app db}`)
83
84
* If you have multiple :db role hosts, it's necessary to specify `:primary => true` on the end of your primary :db server.
85
+
* gem >= 6.0.0 requires SSHKIT >= 1.17.0 as passwords are redacted from logging.
raise('Regeneration of archetype database.yml need the original file to update from.')ifarchetype_file.nil?
46
46
raise('Cannot update a custom postgresql.yml.erb file.')ifFile.exists?(config_file)# Skip custom postgresql.yml.erb if we're updating. It's not supported
47
47
# Update yml file from settings
48
-
iffetch(:pg_generate_random_password) || !fetch(:pg_password)# We need to prevent updating the archetype file if we've done a random or "ask"ed password
Copy file name to clipboardExpand all lines: lib/capistrano/tasks/postgresql.rake
+7-3Lines changed: 7 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -82,12 +82,16 @@ namespace :postgresql do
82
82
end
83
83
end
84
84
85
-
desc'Create pg_username in database'
85
+
desc'Create or update pg_username in database'
86
86
task:create_database_userdo
87
87
onroles:dbdo
88
88
unlessdatabase_user_exists?
89
89
# If you use CREATE USER instead of CREATE ROLE the LOGIN right is granted automatically; otherwise you must specify it in the WITH clause of the CREATE statement.
90
-
psql'execute',fetch(:pg_system_db),'-c',%Q{"CREATE USER \\"#{fetch(:pg_username)}\\" PASSWORD '#{fetch(:pg_password)}';"}
90
+
psql'execute',fetch(:pg_system_db),'-c',%Q{"CREATE USER \\"#{fetch(:pg_username)}\\" PASSWORD},redact("'#{fetch(:pg_password)}'"),%Q{;"}
91
+
end
92
+
ifdatabase_user_password_different?
93
+
# Ensure updating the password in your deploy/ENV.rb files updates the user, server side
94
+
psql'execute',fetch(:pg_system_db),'-c',%Q{"ALTER USER \\"#{fetch(:pg_username)}\\" WITH PASSWORD},redact("'#{fetch(:pg_password)}'"),%Q{;"}
91
95
end
92
96
end
93
97
end
@@ -140,14 +144,14 @@ namespace :postgresql do
140
144
ifrelease_roles(:app).empty?
141
145
warn" WARNING: There are no servers in your app/config/deploy/#{fetch(:rails_env)}.rb with a :app role... Skipping Postgresql setup."
142
146
else
143
-
invoke'postgresql:remove_app_database_yml_files'# Deletes old yml files from all servers. Allows you to avoid having to manually delete the files on your app servers to get a new pool size for example. Don't touch the archetype file to avoid deleting generated passwords.
144
147
ifrelease_roles(:db).empty?# Test to be sure we have a :db role host
145
148
warn" WARNING: There is no server in your app/config/deploy/#{fetch(:rails_env)}.rb with a :db role... Skipping Postgresql setup."
warn" WARNING: There is no :pg_password set in your app/config/deploy/#{fetch(:rails_env)}.rb.\n If you don't wish to set it, 'set :pg_generate_random_password, true' or 'set :pg_ask_for_password, true' are available!"
warn" WARNING: You cannot have both :pg_generate_random_password and :pg_ask_for_password enabled in app/config/deploy/#{fetch(:rails_env)}.rb."
150
153
else
154
+
invoke'postgresql:remove_app_database_yml_files'# Deletes old yml files from all servers. Allows you to avoid having to manually delete the files on your app servers to get a new pool size for example. Don't touch the archetype file to avoid deleting generated passwords.
0 commit comments