From 11f66823eb820e97a4bf6217a5e93da874f402b6 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 29 Dec 2015 21:59:18 -0800 Subject: [PATCH] Configure staging test environment --- config/deploy.rb | 3 ++- config/initializers/postgresql_database_tasks.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 config/initializers/postgresql_database_tasks.rb diff --git a/config/deploy.rb b/config/deploy.rb index f77ee278..3acc1ea2 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -36,7 +36,8 @@ set :nginx_listen, 80 # optional, default is not set set :nginx_roles, :all ## postgresql -#set :pg_user, "thirteen_tien_len_#{fetch(:stage)}" +set :pg_user, "thirteen_tien_len_#{fetch(:stage)}" +set :pg_database, "thirteen_tien_len_#{fetch(:stage)}" namespace :db do desc 'Setup the database' diff --git a/config/initializers/postgresql_database_tasks.rb b/config/initializers/postgresql_database_tasks.rb new file mode 100644 index 00000000..b617cf28 --- /dev/null +++ b/config/initializers/postgresql_database_tasks.rb @@ -0,0 +1,11 @@ +module ActiveRecord + module Tasks + class PostgreSQLDatabaseTasks + def drop + establish_master_connection + connection.select_all "select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where datname='#{configuration['database']}' AND state='idle';" + connection.drop_database configuration['database'] + end + end + end +end