-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to utils, check in pre_migrate signal
- Loading branch information
1 parent
caea879
commit f9d2e28
Showing
3 changed files
with
44 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,22 @@ | ||
# Copyright (c) 2015 Ansible, Inc. | ||
# All Rights Reserved | ||
|
||
import sys | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.db import connection | ||
|
||
from awx.main.utils.db import db_requirement_violations | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Checks connection to the database, and prints out connection info if not connected""" | ||
|
||
def handle(self, *args, **options): | ||
if connection.vendor == 'postgresql': | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute("SELECT version()") | ||
version = str(cursor.fetchone()[0]) | ||
with connection.cursor() as cursor: | ||
cursor.execute("SELECT version()") | ||
version = str(cursor.fetchone()[0]) | ||
|
||
# enforce the postgres version is a minimum of 12 (we need this for partitioning); if not, then terminate program with exit code of 1 | ||
# In the future if we require a feature of a version of postgres > 12 this should be updated to reflect that. | ||
# The return of connection.pg_version is something like 12013 | ||
if (connection.pg_version // 10000) < 12: | ||
self.stderr.write(f"At a minimum, postgres version 12 is required, found {version}\n") | ||
sys.exit(1) | ||
violations = db_requirement_violations() | ||
if violations: | ||
raise CommandError(violations) | ||
|
||
return "Database Version: {}".format(version) | ||
else: | ||
self.stderr.write(f"Running server with '{connection.vendor}' type database is not supported\n") | ||
sys.exit(1) | ||
return "Database Version: {}".format(version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
# Copyright (c) 2017 Ansible by Red Hat | ||
# All Rights Reserved. | ||
|
||
from typing import Optional | ||
|
||
from awx.settings.application_name import set_application_name | ||
from awx import MODE | ||
|
||
from django.conf import settings | ||
from django.db import connection | ||
|
||
|
||
def set_connection_name(function): | ||
set_application_name(settings.DATABASES, settings.CLUSTER_HOST_ID, function=function) | ||
|
||
|
||
MIN_PG_VERSION = 12 | ||
|
||
|
||
def db_requirement_violations() -> Optional[str]: | ||
if connection.vendor == 'postgresql': | ||
|
||
# enforce the postgres version is a minimum of 12 (we need this for partitioning); if not, then terminate program with exit code of 1 | ||
# In the future if we require a feature of a version of postgres > 12 this should be updated to reflect that. | ||
# The return of connection.pg_version is something like 12013 | ||
major_version = connection.pg_version // 10000 | ||
if major_version < MIN_PG_VERSION: | ||
return f"At a minimum, postgres version {MIN_PG_VERSION} is required, found {major_version}\n" | ||
|
||
return None | ||
else: | ||
if MODE == 'production': | ||
return f"Running server with '{connection.vendor}' type database is not supported\n" | ||
return None |