1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Bypass PostgreSQL 9.4 check if database is inaccessible

This commit is contained in:
Jeremy Stretch
2017-10-11 16:28:05 -04:00
parent 392b45e6cb
commit 17a45109f4

View File

@ -1,12 +1,18 @@
from distutils.version import StrictVersion from distutils.version import StrictVersion
from django.db import connection from django.db import connection
from django.db.utils import OperationalError
# NetBox v2.2 and later requires PostgreSQL 9.4 or higher # NetBox v2.2 and later requires PostgreSQL 9.4 or higher.
with connection.cursor() as cursor: try:
cursor.execute("SELECT VERSION()") with connection.cursor() as cursor:
row = cursor.fetchone() cursor.execute("SELECT VERSION()")
pg_version = row[0].split()[1] row = cursor.fetchone()
if StrictVersion(pg_version) < StrictVersion('9.4.0'): pg_version = row[0].split()[1]
raise Exception("PostgreSQL 9.4.0 or higher is required. ({} found)".format(pg_version)) if StrictVersion(pg_version) < StrictVersion('9.4.0'):
raise Exception("PostgreSQL 9.4.0 or higher is required. ({} found)".format(pg_version))
# Skip if the database is missing (e.g. for CI testing) or misconfigured.
except OperationalError:
pass