prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add database connectivity to healthcheck endpoint
  ## Problem
  
  <!-- Describe a problem solved by this feature; or delete the section entirely. -->
  The healtcheck endpoint should check that the database is accessible. If the db is inaccessible, the service is definitively not healthy.
  
  ## Description
  
  <!-- Describe the feature and how it solves the problem. -->
  Add another check (in addition to the ES check) for the database connectivity. Calling `django.db.connection.ensure_connection()` should be sufficient. It raises an error when the database connection is unavailable.
  
  ## Alternatives
  
  <!-- Describe any alternative solutions or features you have considered. How is this feature better? -->
  
  ## Additional context
  
  <!-- Add any other context about the feature here; or delete the section entirely. -->
  
  <!-- If you would like to work on this, please comment below separately. -->
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `api/catalog/api/views/health_views.py`
  Content:
  ```
  1 from django.conf import settings
  2 from rest_framework import status
  3 from rest_framework.exceptions import APIException
  4 from rest_framework.request import Request
  5 from rest_framework.response import Response
  6 from rest_framework.views import APIView
  7 
  8 
  9 class ElasticsearchHealthcheckException(APIException):
  10     status_code = status.HTTP_503_SERVICE_UNAVAILABLE
  11 
  12 
  13 class HealthCheck(APIView):
  14     """
  15     Return a "200 OK" response if the server is running normally, 503 otherwise.
  16 
  17     This endpoint is used in production to ensure that the server should receive
  18     traffic. If no response is provided, the server is deregistered from the
  19     load balancer and destroyed.
  20     """
  21 
  22     swagger_schema = None
  23 
  24     def _check_es(self) -> Response | None:
  25         """Check ES cluster health and raise an exception if ES is not healthy."""
  26 
  27         es_health = settings.ES.cluster.health(timeout="5s")
  28 
  29         if es_health["timed_out"]:
  30             raise ElasticsearchHealthcheckException("es_timed_out")
  31 
  32         if (status := es_health["status"]) != "green":
  33             raise ElasticsearchHealthcheckException(f"es_status_{status}")
  34 
  35     def get(self, request: Request):
  36         if "check_es" in request.query_params:
  37             self._check_es()
  38 
  39         return Response({"status": "200 OK"}, status=200)
  40
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/api/catalog/api/views/health_views.py b/api/catalog/api/views/health_views.py
  --- a/api/catalog/api/views/health_views.py
  +++ b/api/catalog/api/views/health_views.py
  @@ -1,4 +1,5 @@
   from django.conf import settings
  +from django.db import connection
   from rest_framework import status
   from rest_framework.exceptions import APIException
   from rest_framework.request import Request
  @@ -21,19 +22,33 @@
   
       swagger_schema = None
   
  -    def _check_es(self) -> Response | None:
  -        """Check ES cluster health and raise an exception if ES is not healthy."""
  +    @staticmethod
  +    def _check_db() -> None:
  +        """
  +        Check that the database is available.
   
  +        Returns nothing if everything is OK, throws error otherwise.
  +        """
  +        connection.ensure_connection()
  +
  +    @staticmethod
  +    def _check_es() -> None:
  +        """
  +        Check Elasticsearch cluster health.
  +
  +        Raises an exception if ES is not healthy.
  +        """
           es_health = settings.ES.cluster.health(timeout="5s")
   
           if es_health["timed_out"]:
               raise ElasticsearchHealthcheckException("es_timed_out")
   
  -        if (status := es_health["status"]) != "green":
  -            raise ElasticsearchHealthcheckException(f"es_status_{status}")
  +        if (es_status := es_health["status"]) != "green":
  +            raise ElasticsearchHealthcheckException(f"es_status_{es_status}")
   
       def get(self, request: Request):
           if "check_es" in request.query_params:
               self._check_es()
  +        self._check_db()
   
           return Response({"status": "200 OK"}, status=200)
  
verification_info: {"golden_diff": "diff --git a/api/catalog/api/views/health_views.py b/api/catalog/api/views/health_views.py\n--- a/api/catalog/api/views/health_views.py\n+++ b/api/catalog/api/views/health_views.py\n@@ -1,4 +1,5 @@\n from django.conf import settings\n+from django.db import connection\n from rest_framework import status\n from rest_framework.exceptions import APIException\n from rest_framework.request import Request\n@@ -21,19 +22,33 @@\n \n     swagger_schema = None\n \n-    def _check_es(self) -> Response | None:\n-        \"\"\"Check ES cluster health and raise an exception if ES is not healthy.\"\"\"\n+    @staticmethod\n+    def _check_db() -> None:\n+        \"\"\"\n+        Check that the database is available.\n \n+        Returns nothing if everything is OK, throws error otherwise.\n+        \"\"\"\n+        connection.ensure_connection()\n+\n+    @staticmethod\n+    def _check_es() -> None:\n+        \"\"\"\n+        Check Elasticsearch cluster health.\n+\n+        Raises an exception if ES is not healthy.\n+        \"\"\"\n         es_health = settings.ES.cluster.health(timeout=\"5s\")\n \n         if es_health[\"timed_out\"]:\n             raise ElasticsearchHealthcheckException(\"es_timed_out\")\n \n-        if (status := es_health[\"status\"]) != \"green\":\n-            raise ElasticsearchHealthcheckException(f\"es_status_{status}\")\n+        if (es_status := es_health[\"status\"]) != \"green\":\n+            raise ElasticsearchHealthcheckException(f\"es_status_{es_status}\")\n \n     def get(self, request: Request):\n         if \"check_es\" in request.query_params:\n             self._check_es()\n+        self._check_db()\n \n         return Response({\"status\": \"200 OK\"}, status=200)\n", "issue": "Add database connectivity to healthcheck endpoint\n## Problem\r\n\r\n<!-- Describe a problem solved by this feature; or delete the section entirely. -->\r\nThe healtcheck endpoint should check that the database is accessible. If the db is inaccessible, the service is definitively not healthy.\r\n\r\n## Description\r\n\r\n<!-- Describe the feature and how it solves the problem. -->\r\nAdd another check (in addition to the ES check) for the database connectivity. Calling `django.db.connection.ensure_connection()` should be sufficient. It raises an error when the database connection is unavailable.\r\n\r\n## Alternatives\r\n\r\n<!-- Describe any alternative solutions or features you have considered. How is this feature better? -->\r\n\r\n## Additional context\r\n\r\n<!-- Add any other context about the feature here; or delete the section entirely. -->\r\n\r\n<!-- If you would like to work on this, please comment below separately. -->\r\n\n", "before_files": [{"content": "from django.conf import settings\nfrom rest_framework import status\nfrom rest_framework.exceptions import APIException\nfrom rest_framework.request import Request\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\n\n\nclass ElasticsearchHealthcheckException(APIException):\n    status_code = status.HTTP_503_SERVICE_UNAVAILABLE\n\n\nclass HealthCheck(APIView):\n    \"\"\"\n    Return a \"200 OK\" response if the server is running normally, 503 otherwise.\n\n    This endpoint is used in production to ensure that the server should receive\n    traffic. If no response is provided, the server is deregistered from the\n    load balancer and destroyed.\n    \"\"\"\n\n    swagger_schema = None\n\n    def _check_es(self) -> Response | None:\n        \"\"\"Check ES cluster health and raise an exception if ES is not healthy.\"\"\"\n\n        es_health = settings.ES.cluster.health(timeout=\"5s\")\n\n        if es_health[\"timed_out\"]:\n            raise ElasticsearchHealthcheckException(\"es_timed_out\")\n\n        if (status := es_health[\"status\"]) != \"green\":\n            raise ElasticsearchHealthcheckException(f\"es_status_{status}\")\n\n    def get(self, request: Request):\n        if \"check_es\" in request.query_params:\n            self._check_es()\n\n        return Response({\"status\": \"200 OK\"}, status=200)\n", "path": "api/catalog/api/views/health_views.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.db import connection\nfrom rest_framework import status\nfrom rest_framework.exceptions import APIException\nfrom rest_framework.request import Request\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\n\n\nclass ElasticsearchHealthcheckException(APIException):\n    status_code = status.HTTP_503_SERVICE_UNAVAILABLE\n\n\nclass HealthCheck(APIView):\n    \"\"\"\n    Return a \"200 OK\" response if the server is running normally, 503 otherwise.\n\n    This endpoint is used in production to ensure that the server should receive\n    traffic. If no response is provided, the server is deregistered from the\n    load balancer and destroyed.\n    \"\"\"\n\n    swagger_schema = None\n\n    @staticmethod\n    def _check_db() -> None:\n        \"\"\"\n        Check that the database is available.\n\n        Returns nothing if everything is OK, throws error otherwise.\n        \"\"\"\n        connection.ensure_connection()\n\n    @staticmethod\n    def _check_es() -> None:\n        \"\"\"\n        Check Elasticsearch cluster health.\n\n        Raises an exception if ES is not healthy.\n        \"\"\"\n        es_health = settings.ES.cluster.health(timeout=\"5s\")\n\n        if es_health[\"timed_out\"]:\n            raise ElasticsearchHealthcheckException(\"es_timed_out\")\n\n        if (es_status := es_health[\"status\"]) != \"green\":\n            raise ElasticsearchHealthcheckException(f\"es_status_{es_status}\")\n\n    def get(self, request: Request):\n        if \"check_es\" in request.query_params:\n            self._check_es()\n        self._check_db()\n\n        return Response({\"status\": \"200 OK\"}, status=200)\n", "path": "api/catalog/api/views/health_views.py"}]}