2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-10-02 14:25:04 +00:00
|
|
|
namespace :zammad do
|
|
|
|
|
|
|
|
namespace :db do
|
|
|
|
|
2018-10-18 12:20:51 +00:00
|
|
|
desc 'Drops, recreates and seeds the database, clears the Cache and reloads the Settings'
|
2018-10-02 14:25:04 +00:00
|
|
|
task reset: :environment do
|
2018-10-18 12:20:51 +00:00
|
|
|
|
|
|
|
# we loop over each dependent task to be able to
|
|
|
|
# execute them and their prerequisites multiple times (in tests)
|
2020-08-13 07:47:51 +00:00
|
|
|
# there is no way in rake to achieve that
|
2021-07-22 14:01:34 +00:00
|
|
|
%w[db:drop:_unsafe db:create db:migrate db:seed zammad:db:rebuild].each do |task|
|
2018-10-18 12:20:51 +00:00
|
|
|
|
2021-06-23 11:35:27 +00:00
|
|
|
if task == 'db:drop:_unsafe'
|
|
|
|
# ensure all DB connections are closed before dropping the DB
|
|
|
|
# since Rails > 5.2 two connections are present (after `db:migrate`) that
|
|
|
|
# block dropping the DB for PostgreSQL
|
|
|
|
ActiveRecord::Base.connection_handler.connection_pools.each(&:disconnect!)
|
|
|
|
end
|
|
|
|
|
2020-08-19 08:32:00 +00:00
|
|
|
$stdout = StringIO.new if task == 'db:migrate'.freeze
|
2019-06-27 18:26:28 +00:00
|
|
|
|
|
|
|
Rake::Task[task].reenable
|
|
|
|
Rake::Task[task].invoke
|
|
|
|
ensure
|
|
|
|
$stdout = STDOUT
|
2018-10-18 12:20:51 +00:00
|
|
|
end
|
2018-10-02 14:25:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|