Skip to content

Commit ff6184b

Browse files
committed
Django3: remove old non-JSONFields and kept the new ones only
``` In [3]: Build.objects.filter(_config__build__image='readthedocs/build:latest') Out[3]: <BuildQuerySet [<Build: Build qtile for admin (2)>, <Build: Build qtile for admin (1)>]> ```
1 parent bc8cee0 commit ff6184b

File tree

5 files changed

+70
-10
lines changed

5 files changed

+70
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.2.11 on 2022-01-31 12:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('builds', '0038_add_new_jsonfields'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='build',
15+
name='_config',
16+
),
17+
migrations.RenameField(
18+
model_name='build',
19+
old_name='_config_json',
20+
new_name='_config',
21+
),
22+
]

readthedocs/builds/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
ModificationDateTimeField,
2121
)
2222
from django_extensions.db.models import TimeStampedModel
23-
from jsonfield import JSONField
2423
from polymorphic.models import PolymorphicModel
2524

2625
import readthedocs.builds.automation_actions as actions
@@ -647,8 +646,7 @@ class Build(models.Model):
647646
null=True,
648647
blank=True,
649648
)
650-
_config = JSONField(_('Configuration used in the build'), default=dict)
651-
_config_json = models.JSONField(_('Configuration used in the build'), default=dict)
649+
_config = models.JSONField(_('Configuration used in the build'), default=dict)
652650

653651
length = models.IntegerField(_('Build Length'), null=True, blank=True)
654652

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Generated by Django 3.2.11 on 2022-01-31 12:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('integrations', '0008_add_new_jsonfields'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='httpexchange',
15+
name='request_headers',
16+
),
17+
migrations.RemoveField(
18+
model_name='httpexchange',
19+
name='response_headers',
20+
),
21+
migrations.RemoveField(
22+
model_name='integration',
23+
name='provider_data',
24+
),
25+
migrations.RenameField(
26+
model_name='httpexchange',
27+
old_name='request_headers_json',
28+
new_name='request_headers',
29+
),
30+
migrations.RenameField(
31+
model_name='httpexchange',
32+
old_name='response_headers_json',
33+
new_name='response_headers',
34+
),
35+
migrations.RenameField(
36+
model_name='integration',
37+
old_name='provider_data_json',
38+
new_name='provider_data',
39+
),
40+
]

readthedocs/integrations/models.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from django.db import models, transaction
1313
from django.utils.safestring import mark_safe
1414
from django.utils.translation import gettext_lazy as _
15-
from jsonfield import JSONField
1615
from pygments import highlight
1716
from pygments.formatters import HtmlFormatter
1817
from pygments.lexers import JsonLexer
@@ -144,17 +143,15 @@ class HttpExchange(models.Model):
144143

145144
date = models.DateTimeField(_('Date'), auto_now_add=True)
146145

147-
request_headers = JSONField(_('Request headers'))
148-
request_headers_json = models.JSONField(
146+
request_headers = models.JSONField(
149147
_('Request headers'),
150148
# Delete after deploy
151149
null=True,
152150
default=None,
153151
)
154152
request_body = models.TextField(_('Request body'))
155153

156-
response_headers = JSONField(_('Request headers'))
157-
response_headers_json = models.JSONField(
154+
response_headers = models.JSONField(
158155
_('Request headers'),
159156
# Delete after deploy
160157
null=True,
@@ -289,8 +286,7 @@ class Integration(models.Model):
289286
max_length=32,
290287
choices=INTEGRATIONS,
291288
)
292-
provider_data = JSONField(_('Provider data'), default=dict)
293-
provider_data_json = models.JSONField(_('Provider data'), default=dict)
289+
provider_data = models.JSONField(_('Provider data'), default=dict)
294290
exchanges = GenericRelation(
295291
'HttpExchange',
296292
related_query_name='integrations',

requirements/pip.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ drf-flex-fields==0.9.7
2121
drf-extensions==0.7.1
2222

2323
django-vanilla-views==3.0.0
24+
25+
# This module is only used on migrations. We are now using Django's official
26+
# JSONField. We should probably squash these migrations and remove this
27+
# dependency as well.
2428
jsonfield==3.1.0
2529

2630
requests==2.27.1

0 commit comments

Comments
 (0)