DEV: Add rake task to check that the DB can be accessed (#14300)

DEV: Add rake task to check that the DB can be accessed (#14300)

diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake
index 9f3c6fc..3230357 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

GitHub sha: 05c356f7c6fdfc4a9067c1312d8384512c5044b1

This commit appears in #14300 which was approved by eviltrout. It was merged by danielwaterworth.