Skip to content

Commit

Permalink
Merge pull request #37 from capistrano-plugins/v4.4.0
Browse files Browse the repository at this point in the history
V4.4.0: database.yml cleanup
  • Loading branch information
NorseGaud authored Oct 24, 2017
2 parents f11521a + dcb0011 commit 9980bb3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
Gemfile.lock
*.gem
2 changes: 1 addition & 1 deletion lib/capistrano/postgresql/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Capistrano
module Postgresql
VERSION = "4.3.1"
VERSION = "4.4.0"
end
end
38 changes: 26 additions & 12 deletions lib/capistrano/tasks/postgresql.rake
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ namespace :postgresql do
end
end

task :remove_yml_files do
on release_roles :all do
if test "[ -e #{database_yml_file} ]"
execute :rm, database_yml_file
end
end
on primary :db do
if test "[ -e #{archetype_database_yml_file} ]"
execute :rm, archetype_database_yml_file
end
end
end

desc 'Remove pg_extension from postgresql db'
task :remove_extensions do
next unless Array( fetch(:pg_extensions) ).any?
on roles :db do
# remove in reverse order if extension is present
Array( fetch(:pg_extensions) ).reverse.each do |ext|
psql_on_app_db '-c', %Q{"DROP EXTENSION IF EXISTS #{ext};"} unless [nil, false, ""].include?(ext)
end
end
end

desc 'Add the hstore extension to postgresql'
task :add_hstore do
next unless fetch(:pg_use_hstore)
Expand All @@ -77,18 +101,7 @@ namespace :postgresql do
on roles :db do
# add extensions if extension is present
Array( fetch(:pg_extensions) ).each do |ext|
psql_on_app_db '-c', %Q{"CREATE EXTENSION IF NOT EXISTS \\"#{ext}\\";"} unless [nil, false, ""].include?(ext)
end
end
end

desc 'Remove pg_extension from postgresql db'
task :remove_extensions do
next unless Array( fetch(:pg_extensions) ).any?
on roles :db do
# remove in reverse order if extension is present
Array( fetch(:pg_extensions) ).reverse.each do |ext|
psql_on_app_db '-c', %Q{"DROP EXTENSION IF EXISTS \\"#{ext}\\";"} unless [nil, false, ""].include?(ext)
psql_on_app_db '-c', %Q{"CREATE EXTENSION IF NOT EXISTS #{ext};"} unless [nil, false, ""].include?(ext)
end
end
end
Expand Down Expand Up @@ -149,6 +162,7 @@ namespace :postgresql do

desc 'Postgresql setup tasks'
task :setup do
invoke 'postgresql:remove_yml_files' # Delete old yml files. Allows you to avoid having to manually delete the files on your web/app servers to get a new pool size for example.
invoke 'postgresql:create_db_user'
invoke 'postgresql:create_database'
invoke 'postgresql:add_hstore'
Expand Down

0 comments on commit 9980bb3

Please sign in to comment.