|
1 | 1 | # Copyright (c) 2015 Ansible, Inc.
|
2 | 2 | # All Rights Reserved
|
3 | 3 |
|
4 |
| -import sys |
5 |
| - |
6 |
| -from django.core.management.base import BaseCommand |
| 4 | +from django.core.management.base import BaseCommand, CommandError |
7 | 5 | from django.db import connection
|
8 | 6 |
|
| 7 | +from awx.main.utils.db import db_requirement_violations |
| 8 | + |
9 | 9 |
|
10 | 10 | class Command(BaseCommand):
|
11 | 11 | """Checks connection to the database, and prints out connection info if not connected"""
|
12 | 12 |
|
13 | 13 | def handle(self, *args, **options):
|
14 |
| - if connection.vendor == 'postgresql': |
15 |
| - |
16 |
| - with connection.cursor() as cursor: |
17 |
| - cursor.execute("SELECT version()") |
18 |
| - version = str(cursor.fetchone()[0]) |
| 14 | + with connection.cursor() as cursor: |
| 15 | + cursor.execute("SELECT version()") |
| 16 | + version = str(cursor.fetchone()[0]) |
19 | 17 |
|
20 |
| - # enforce the postgres version is a minimum of 12 (we need this for partitioning); if not, then terminate program with exit code of 1 |
21 |
| - # In the future if we require a feature of a version of postgres > 12 this should be updated to reflect that. |
22 |
| - # The return of connection.pg_version is something like 12013 |
23 |
| - if (connection.pg_version // 10000) < 12: |
24 |
| - self.stderr.write(f"At a minimum, postgres version 12 is required, found {version}\n") |
25 |
| - sys.exit(1) |
| 18 | + violations = db_requirement_violations() |
| 19 | + if violations: |
| 20 | + raise CommandError(violations) |
26 | 21 |
|
27 |
| - return "Database Version: {}".format(version) |
28 |
| - else: |
29 |
| - self.stderr.write(f"Running server with '{connection.vendor}' type database is not supported\n") |
30 |
| - sys.exit(1) |
| 22 | + return "Database Version: {}".format(version) |
0 commit comments