Skip to content

Commit

Permalink
#7 - Fixing rake shards:test:purge to run in test shards
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-nogueira committed Nov 6, 2019
1 parent 2207461 commit bd6a099
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/tasks/rails-sharding.rake
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,17 @@ shards_namespace = namespace :shards do
should_reconnect = Rails::Sharding::ConnectionHandler.connection_pool(shard_group, shard).active_connection?
Rails::Sharding::ConnectionHandler.establish_connection(shard_group, shard, 'test')

# saves the current RAILS_ENV (we must change it so the environment is set correcly on the metadata table)
initial_rails_env = Rails.env
Rails.env = 'test'

Rails::Sharding.using_shard(shard_group, shard) do
ActiveRecord::Tasks::DatabaseTasks.purge(configuration)
end
ensure
# restores rails env
Rails.env = initial_rails_env

if should_reconnect
# reestablishes connection for RAILS_ENV environment (whatever that is)
Rails::Sharding::ConnectionHandler.establish_connection(shard_group, shard)
Expand Down

0 comments on commit bd6a099

Please sign in to comment.