mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 11:37:21 -06:00
Refactor Extras Migration Version Check (#2604)
* Add constant for DB_MINIMUM_VERSION * Refactor verify_postgresql_version to use Django connection pg_version method for comparing versions. * Remove StrictVersion import * Remove DB_MINIMUM_VERSION as not necessary in constants. * Define DB_MINIMUM_VERSION locally to freeze to migration. * Refactor database version verification to use django builtin methods.
This commit is contained in:
parent
34bfb899d1
commit
f052bbc36e
@ -2,9 +2,6 @@
|
|||||||
# Generated by Django 1.11.14 on 2018-07-31 02:19
|
# Generated by Django 1.11.14 on 2018-07-31 02:19
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
from distutils.version import StrictVersion
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import django.contrib.postgres.fields.jsonb
|
import django.contrib.postgres.fields.jsonb
|
||||||
from django.db import connection, migrations, models
|
from django.db import connection, migrations, models
|
||||||
@ -19,13 +16,14 @@ def verify_postgresql_version(apps, schema_editor):
|
|||||||
"""
|
"""
|
||||||
Verify that PostgreSQL is version 9.4 or higher.
|
Verify that PostgreSQL is version 9.4 or higher.
|
||||||
"""
|
"""
|
||||||
|
# https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQSERVERVERSION
|
||||||
|
DB_MINIMUM_VERSION = 90400 # 9.4.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with connection.cursor() as cursor:
|
pg_version = connection.pg_version
|
||||||
cursor.execute("SELECT VERSION()")
|
|
||||||
row = cursor.fetchone()
|
if pg_version < DB_MINIMUM_VERSION:
|
||||||
pg_version = re.match(r'^PostgreSQL (\d+\.\d+(\.\d+)?)', row[0]).group(1)
|
raise Exception("PostgreSQL 9.4.0 ({}) or higher is required ({} found). Upgrade PostgreSQL and then run migrations again.".format(DB_MINIMUM_VERSION, pg_version))
|
||||||
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))
|
|
||||||
|
|
||||||
# Skip if the database is missing (e.g. for CI testing) or misconfigured.
|
# Skip if the database is missing (e.g. for CI testing) or misconfigured.
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.11.4 on 2017-09-26 21:25
|
# Generated by Django 1.11.4 on 2017-09-26 21:25
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from distutils.version import StrictVersion
|
|
||||||
import re
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import django.contrib.postgres.fields.jsonb
|
import django.contrib.postgres.fields.jsonb
|
||||||
@ -15,13 +13,14 @@ def verify_postgresql_version(apps, schema_editor):
|
|||||||
"""
|
"""
|
||||||
Verify that PostgreSQL is version 9.4 or higher.
|
Verify that PostgreSQL is version 9.4 or higher.
|
||||||
"""
|
"""
|
||||||
|
# https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQSERVERVERSION
|
||||||
|
DB_MINIMUM_VERSION = 90400 # 9.4.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with connection.cursor() as cursor:
|
pg_version = connection.pg_version
|
||||||
cursor.execute("SELECT VERSION()")
|
|
||||||
row = cursor.fetchone()
|
if pg_version < DB_MINIMUM_VERSION:
|
||||||
pg_version = re.match(r'^PostgreSQL (\d+\.\d+(\.\d+)?)', row[0]).group(1)
|
raise Exception("PostgreSQL 9.4.0 ({}) or higher is required ({} found). Upgrade PostgreSQL and then run migrations again.".format(DB_MINIMUM_VERSION, pg_version))
|
||||||
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))
|
|
||||||
|
|
||||||
# Skip if the database is missing (e.g. for CI testing) or misconfigured.
|
# Skip if the database is missing (e.g. for CI testing) or misconfigured.
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
|
Loading…
Reference in New Issue
Block a user