From 0935df47612cd9b5f9407432d881bdee6f37ec0a Mon Sep 17 00:00:00 2001 From: txb5022 Date: Tue, 20 Nov 2018 16:39:06 -0500 Subject: [PATCH] Refactor verify_postgresql_version to use Django connection pg_version method for comparing versions. --- ...itial_squashed_0010_customfield_filter_logic.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/netbox/extras/migrations/0001_initial_squashed_0010_customfield_filter_logic.py b/netbox/extras/migrations/0001_initial_squashed_0010_customfield_filter_logic.py index 0ac826ba4..20ca32a4e 100644 --- a/netbox/extras/migrations/0001_initial_squashed_0010_customfield_filter_logic.py +++ b/netbox/extras/migrations/0001_initial_squashed_0010_customfield_filter_logic.py @@ -2,7 +2,6 @@ # Generated by Django 1.11.14 on 2018-07-31 02:19 from __future__ import unicode_literals -import re from distutils.version import StrictVersion from django.conf import settings @@ -12,7 +11,8 @@ import django.db.models.deletion import extras.models from django.db.utils import OperationalError -from extras.constants import CF_FILTER_DISABLED, CF_FILTER_EXACT, CF_FILTER_LOOSE, CF_TYPE_SELECT +from extras.constants import (CF_FILTER_DISABLED, CF_FILTER_EXACT, CF_FILTER_LOOSE, + CF_TYPE_SELECT, DB_MINIMUM_VERSION) def verify_postgresql_version(apps, schema_editor): @@ -20,12 +20,10 @@ def verify_postgresql_version(apps, schema_editor): Verify that PostgreSQL is version 9.4 or higher. """ try: - with connection.cursor() as cursor: - cursor.execute("SELECT VERSION()") - row = cursor.fetchone() - pg_version = re.match(r'^PostgreSQL (\d+\.\d+(\.\d+)?)', row[0]).group(1) - if StrictVersion(pg_version) < StrictVersion('9.4.0'): - raise Exception("PostgreSQL 9.4.0 or higher is required ({} found). Upgrade PostgreSQL and then run migrations again.".format(pg_version)) + pg_version = connection.pg_version + + if pg_version < DB_MINIMUM_VERSION: + raise Exception("PostgreSQL 9.4.0 ({}) or higher is required ({} found). Upgrade PostgreSQL and then run migrations again.".format(DB_MINIMUM_VERSION, pg_version)) # Skip if the database is missing (e.g. for CI testing) or misconfigured. except OperationalError: