Skip to content

A platform for community discussion. Free, open, simple.

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

Daniel Waterworth05c356f7c6fd
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