|
|
@@ -1,9 +1,11 @@
|
|
|
from django.apps import apps
|
|
|
-from django.core.checks import Error, Tags, register
|
|
|
+from django.core.checks import Error, Tags, Warning, register
|
|
|
+from django.db import connection
|
|
|
from django.db.models import Index, UniqueConstraint
|
|
|
|
|
|
__all__ = (
|
|
|
'check_duplicate_indexes',
|
|
|
+ 'check_postgresql_version',
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -39,3 +41,29 @@ def check_duplicate_indexes(app_configs, **kwargs):
|
|
|
)
|
|
|
|
|
|
return errors
|
|
|
+
|
|
|
+
|
|
|
+@register(Tags.database)
|
|
|
+def check_postgresql_version(app_configs, **kwargs):
|
|
|
+ """
|
|
|
+ Warn if the PostgreSQL version is less than 15, as support for PostgreSQL 14
|
|
|
+ will be removed in NetBox v4.7.
|
|
|
+ """
|
|
|
+ warnings = []
|
|
|
+ try:
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ cursor.execute('SHOW server_version_num')
|
|
|
+ row = cursor.fetchone()
|
|
|
+ pg_version = int(row[0])
|
|
|
+ if pg_version < 150000:
|
|
|
+ major_version = pg_version // 10000
|
|
|
+ warnings.append(
|
|
|
+ Warning(
|
|
|
+ f'Support for PostgreSQL {major_version} is deprecated and will be removed in NetBox v4.7.',
|
|
|
+ hint='Please upgrade to PostgreSQL 15 or later.',
|
|
|
+ id='netbox.W001',
|
|
|
+ )
|
|
|
+ )
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+ return warnings
|