diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4a140f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +Gemfile.lock +*.gem \ No newline at end of file diff --git a/lib/capistrano/postgresql/version.rb b/lib/capistrano/postgresql/version.rb index 0c97ff3..c832800 100644 --- a/lib/capistrano/postgresql/version.rb +++ b/lib/capistrano/postgresql/version.rb @@ -1,5 +1,5 @@ module Capistrano module Postgresql - VERSION = "4.3.1" + VERSION = "4.4.0" end end diff --git a/lib/capistrano/tasks/postgresql.rake b/lib/capistrano/tasks/postgresql.rake index a83d345..c5ba8bd 100644 --- a/lib/capistrano/tasks/postgresql.rake +++ b/lib/capistrano/tasks/postgresql.rake @@ -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) @@ -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 @@ -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'