Better database connection check

Fixes the MySQL output and adds a rake task to properly check the connection

This will e.g., output something like this

```
Database connection failed with error: FATAL:  Datenbank »bla« existiert nicht
```
pull/9187/head
Oliver Günther 4 years ago
parent 12cf765431
commit 412302a093
  1. 17
      lib/tasks/database.rake
  2. 6
      packaging/scripts/check

@ -41,7 +41,22 @@ end
namespace 'openproject' do
namespace 'db' do
desc 'Ensure database version compatibility'
task ensure_database_compatibility: ['environment', 'db:load_config'] do
task check_connection: %w[environment db:load_config] do
begin
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.execute "SELECT 1;"
unless ActiveRecord::Base.connected?
puts "Database connection failed"
Kernel.exit 1
end
rescue StandardError => e
puts "Database connection failed with error: #{e}"
Kernel.exit 1
end
end
desc 'Ensure database version compatibility'
task ensure_database_compatibility: %w[openproject:db:check_connection] do
##
# Ensure database server version is compatible
OpenProject::Database::check!

@ -11,10 +11,10 @@ log_ko() {
}
# try to get a setting to make sure database connection works
if rake setting:get[protocol] &>/dev/null; then
log_ok "MySQL configuration is working"
if rake openproject:db:check_connection 2>/dev/null; then
log_ok "PostgreSQL configuration is working"
else
log_ko "MySQL connection is NOT working"
log_ko "PostgreSQL connection is NOT working"
fi
if ps -u "$SERVER_USER" &>/dev/null ; then

Loading…
Cancel
Save