|
@@ -1,10 +1,12 @@
|
|
|
from django.apps import apps
|
|
from django.apps import apps
|
|
|
from django.core.cache import cache
|
|
from django.core.cache import cache
|
|
|
from django.core.checks import Error, Tags, register
|
|
from django.core.checks import Error, Tags, register
|
|
|
|
|
+from django.db import NotSupportedError, connection
|
|
|
from django.db.models import Index, UniqueConstraint
|
|
from django.db.models import Index, UniqueConstraint
|
|
|
|
|
|
|
|
__all__ = (
|
|
__all__ = (
|
|
|
'check_duplicate_indexes',
|
|
'check_duplicate_indexes',
|
|
|
|
|
+ 'check_postgresql_version',
|
|
|
'check_redis_version',
|
|
'check_redis_version',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -43,6 +45,47 @@ def check_duplicate_indexes(app_configs, **kwargs):
|
|
|
return errors
|
|
return errors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@register(Tags.database)
|
|
|
|
|
+def check_postgresql_version(app_configs, **kwargs):
|
|
|
|
|
+ """
|
|
|
|
|
+ Report an error if the PostgreSQL version is less than 15.
|
|
|
|
|
+ """
|
|
|
|
|
+ errors = []
|
|
|
|
|
+ try:
|
|
|
|
|
+ with connection.cursor() as cursor:
|
|
|
|
|
+ cursor.execute('SHOW server_version_num')
|
|
|
|
|
+ row = cursor.fetchone()
|
|
|
|
|
+ pg_version = int(row[0])
|
|
|
|
|
+ except NotSupportedError:
|
|
|
|
|
+ # Django's own backend check rejects the connection outright when the server predates the
|
|
|
|
|
+ # minimum version Django supports (BaseDatabaseWrapper.init_connection_state()), so the query
|
|
|
|
|
+ # above never runs. Report the requirement here rather than letting the raw exception surface
|
|
|
|
|
+ # as a traceback: management commands run system checks with databases=None, which skips
|
|
|
|
|
+ # Django's equivalent check, so this is the only opportunity to report it cleanly.
|
|
|
|
|
+ errors.append(
|
|
|
|
|
+ Error(
|
|
|
|
|
+ 'The configured PostgreSQL version is not supported. NetBox requires PostgreSQL 15 or later.',
|
|
|
|
|
+ hint='Please upgrade to PostgreSQL 15 or later.',
|
|
|
|
|
+ id='netbox.E001',
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ # The database may be unreachable (e.g. when running checks before it has been provisioned).
|
|
|
|
|
+ # Leave the version unverified rather than reporting a spurious error.
|
|
|
|
|
+ pass
|
|
|
|
|
+ else:
|
|
|
|
|
+ if pg_version < 150000:
|
|
|
|
|
+ major_version = pg_version // 10000
|
|
|
|
|
+ errors.append(
|
|
|
|
|
+ Error(
|
|
|
|
|
+ f'PostgreSQL {major_version} is not supported. NetBox requires PostgreSQL 15 or later.',
|
|
|
|
|
+ hint='Please upgrade to PostgreSQL 15 or later.',
|
|
|
|
|
+ id='netbox.E001',
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ return errors
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@register(Tags.caches)
|
|
@register(Tags.caches)
|
|
|
def check_redis_version(app_configs, **kwargs):
|
|
def check_redis_version(app_configs, **kwargs):
|
|
|
"""
|
|
"""
|