From c0fd70f189a273af223c0ef039802d78eed334f0 Mon Sep 17 00:00:00 2001 From: Christian Adams Date: Tue, 1 Oct 2019 14:39:46 -0400 Subject: [PATCH] add mgmt cmd to check db connection --- awx/main/management/commands/check_db.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 awx/main/management/commands/check_db.py diff --git a/awx/main/management/commands/check_db.py b/awx/main/management/commands/check_db.py new file mode 100644 index 0000000000..e72b86873c --- /dev/null +++ b/awx/main/management/commands/check_db.py @@ -0,0 +1,17 @@ +# Copyright (c) 2015 Ansible, Inc. +# All Rights Reserved + +from django.core.management.base import BaseCommand +from django.db import connection + + +class Command(BaseCommand): + """Checks connection to the database, and prints out connection info if not connected""" + + def handle(self, *args, **options): + + with connection.cursor() as cursor: + cursor.execute("SELECT version()") + version = str(cursor.fetchone()[0]) + + return "Database Version: {}".format(version)