From 05c356f7c6fdfc4a9067c1312d8384512c5044b1 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Thu, 9 Sep 2021 14:42:10 -0500 Subject: [PATCH] DEV: Add rake task to check that the DB can be accessed (#14300) --- lib/tasks/db.rake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 9f3c6fc7f97..3230357df38 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -545,3 +545,15 @@ task 'db:rebuild_indexes' => 'environment' do Discourse.disable_readonly_mode end end + +desc 'Check that the DB can be accessed' +task 'db:status:json' do + begin + Rake::Task['environment'].invoke + DB.query('SELECT 1') + rescue + puts({ status: 'error' }.to_json) + else + puts({ status: 'ok' }.to_json) + end +end