From 21a750e8ec7bb02e7ab471e685ab931f8f8ec82e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 16 Jul 2020 12:02:49 -0400 Subject: [PATCH] Change Postgres-specific JSONField to stock Django field --- .../dcim/migrations/0114_update_jsonfield.py | 23 +++++++++++++++ netbox/dcim/models/__init__.py | 4 +-- .../migrations/0046_update_jsonfield.py | 28 +++++++++++++++++++ netbox/extras/models/change_logging.py | 3 +- netbox/extras/models/models.py | 7 ++--- .../users/migrations/0010_update_jsonfield.py | 23 +++++++++++++++ netbox/users/models.py | 6 ++-- .../migrations/0017_update_jsonfield.py | 18 ++++++++++++ 8 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 netbox/dcim/migrations/0114_update_jsonfield.py create mode 100644 netbox/extras/migrations/0046_update_jsonfield.py create mode 100644 netbox/users/migrations/0010_update_jsonfield.py create mode 100644 netbox/virtualization/migrations/0017_update_jsonfield.py diff --git a/netbox/dcim/migrations/0114_update_jsonfield.py b/netbox/dcim/migrations/0114_update_jsonfield.py new file mode 100644 index 000000000..5a971bced --- /dev/null +++ b/netbox/dcim/migrations/0114_update_jsonfield.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1b1 on 2020-07-16 16:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0113_nullbooleanfield_to_booleanfield'), + ] + + operations = [ + migrations.AlterField( + model_name='device', + name='local_context_data', + field=models.JSONField(blank=True, null=True), + ), + migrations.AlterField( + model_name='platform', + name='napalm_args', + field=models.JSONField(blank=True, null=True), + ), + ] diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index 9f4b23603..5e3f57e0e 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -6,7 +6,7 @@ from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import ArrayField, JSONField +from django.contrib.postgres.fields import ArrayField from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models @@ -1280,7 +1280,7 @@ class Platform(ChangeLoggedModel): verbose_name='NAPALM driver', help_text='The name of the NAPALM driver to use when interacting with devices' ) - napalm_args = JSONField( + napalm_args = models.JSONField( blank=True, null=True, verbose_name='NAPALM arguments', diff --git a/netbox/extras/migrations/0046_update_jsonfield.py b/netbox/extras/migrations/0046_update_jsonfield.py new file mode 100644 index 000000000..a06302840 --- /dev/null +++ b/netbox/extras/migrations/0046_update_jsonfield.py @@ -0,0 +1,28 @@ +# Generated by Django 3.1b1 on 2020-07-16 16:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0045_configcontext_changelog'), + ] + + operations = [ + migrations.AlterField( + model_name='configcontext', + name='data', + field=models.JSONField(), + ), + migrations.AlterField( + model_name='jobresult', + name='data', + field=models.JSONField(blank=True, null=True), + ), + migrations.AlterField( + model_name='objectchange', + name='object_data', + field=models.JSONField(editable=False), + ), + ] diff --git a/netbox/extras/models/change_logging.py b/netbox/extras/models/change_logging.py index 3260c5302..bec8e2b75 100644 --- a/netbox/extras/models/change_logging.py +++ b/netbox/extras/models/change_logging.py @@ -1,7 +1,6 @@ from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import JSONField from django.db import models from django.urls import reverse @@ -104,7 +103,7 @@ class ObjectChange(models.Model): max_length=200, editable=False ) - object_data = JSONField( + object_data = models.JSONField( editable=False ) diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index edd13a123..fcfcfefb3 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -5,7 +5,6 @@ from collections import OrderedDict from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import JSONField from django.core.validators import ValidationError from django.db import models from django.http import HttpResponse @@ -499,7 +498,7 @@ class ConfigContext(ChangeLoggedModel): related_name='+', blank=True ) - data = JSONField() + data = models.JSONField() objects = ConfigContextQuerySet.as_manager() @@ -526,7 +525,7 @@ class ConfigContextModel(models.Model): A model which includes local configuration context data. This local data will override any inherited data from ConfigContexts. """ - local_context_data = JSONField( + local_context_data = models.JSONField( blank=True, null=True, ) @@ -627,7 +626,7 @@ class JobResult(models.Model): choices=JobResultStatusChoices, default=JobResultStatusChoices.STATUS_PENDING ) - data = JSONField( + data = models.JSONField( null=True, blank=True ) diff --git a/netbox/users/migrations/0010_update_jsonfield.py b/netbox/users/migrations/0010_update_jsonfield.py new file mode 100644 index 000000000..1935e58b7 --- /dev/null +++ b/netbox/users/migrations/0010_update_jsonfield.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1b1 on 2020-07-16 16:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0009_replicate_permissions'), + ] + + operations = [ + migrations.AlterField( + model_name='objectpermission', + name='constraints', + field=models.JSONField(blank=True, null=True), + ), + migrations.AlterField( + model_name='userconfig', + name='data', + field=models.JSONField(default=dict), + ), + ] diff --git a/netbox/users/models.py b/netbox/users/models.py index f210cb4d0..9e890cfdf 100644 --- a/netbox/users/models.py +++ b/netbox/users/models.py @@ -3,7 +3,7 @@ import os from django.contrib.auth.models import Group, User from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import ArrayField, JSONField +from django.contrib.postgres.fields import ArrayField from django.core.validators import MinLengthValidator from django.db import models from django.db.models.signals import post_save @@ -56,7 +56,7 @@ class UserConfig(models.Model): on_delete=models.CASCADE, related_name='config' ) - data = JSONField( + data = models.JSONField( default=dict ) @@ -265,7 +265,7 @@ class ObjectPermission(models.Model): base_field=models.CharField(max_length=30), help_text="The list of actions granted by this permission" ) - constraints = JSONField( + constraints = models.JSONField( blank=True, null=True, help_text="Queryset filter matching the applicable objects of the selected type(s)" diff --git a/netbox/virtualization/migrations/0017_update_jsonfield.py b/netbox/virtualization/migrations/0017_update_jsonfield.py new file mode 100644 index 000000000..2a23deef6 --- /dev/null +++ b/netbox/virtualization/migrations/0017_update_jsonfield.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1b1 on 2020-07-16 16:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('virtualization', '0016_replicate_interfaces'), + ] + + operations = [ + migrations.AlterField( + model_name='virtualmachine', + name='local_context_data', + field=models.JSONField(blank=True, null=True), + ), + ]