Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Better database connection check

Oliver Günther412302a09307
diff --git a/lib/tasks/database.rake b/lib/tasks/database.rake
index d5477e8bfa5..5e243a828e3 100644
--- a/lib/tasks/database.rake
+++ b/lib/tasks/database.rake
@@ -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!
diff --git a/packaging/scripts/check b/packaging/scripts/check
index bf019714150..25addd348cf 100755
--- a/packaging/scripts/check
+++ b/packaging/scripts/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