Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate JSONField to Django builtin JSONField #919

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions adserver/analyzer/migrations/0008_migrate_jsonfield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 5.0.8 on 2024-09-30 21:04

import adserver.analyzer.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("adserver_analyzer", "0007_add_advertiser_flights"),
]

operations = [
migrations.AlterField(
model_name="analyzedadvertiserurl",
name="keywords",
field=models.JSONField(
blank=True,
null=True,
validators=[adserver.analyzer.validators.KeywordsValidator()],
verbose_name="Keywords for this URL",
),
),
migrations.AlterField(
model_name="analyzedurl",
name="keywords",
field=models.JSONField(
blank=True,
null=True,
validators=[adserver.analyzer.validators.KeywordsValidator()],
verbose_name="Keywords for this URL",
),
),
]
3 changes: 1 addition & 2 deletions adserver/analyzer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django_extensions.db.models import TimeStampedModel
from jsonfield import JSONField

from ..models import Advertiser
from ..models import Flight
Expand All @@ -21,7 +20,7 @@ class BaseAnalyzedUrl(TimeStampedModel):
)

# Fields below are updated by the analyzer
keywords = JSONField(
keywords = models.JSONField(
_("Keywords for this URL"),
blank=True,
null=True,
Expand Down
110 changes: 110 additions & 0 deletions adserver/migrations/0097_migrate_jsonfield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Generated by Django 5.0.8 on 2024-09-30 21:04

import adserver.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("adserver", "0096_simple_history_upgrade"),
]

operations = [
migrations.AlterField(
model_name="click",
name="keywords",
field=models.JSONField(
blank=True, null=True, verbose_name="Keyword targeting for this view"
),
),
migrations.AlterField(
model_name="flight",
name="targeting_parameters",
field=models.JSONField(
blank=True,
null=True,
validators=[adserver.validators.TargetingParametersValidator()],
verbose_name="Targeting parameters",
),
),
migrations.AlterField(
model_name="flight",
name="traffic_cap",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[adserver.validators.TrafficFillValidator()],
verbose_name="Traffic cap",
),
),
migrations.AlterField(
model_name="flight",
name="traffic_fill",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[adserver.validators.TrafficFillValidator()],
verbose_name="Traffic fill",
),
),
migrations.AlterField(
model_name="historicalflight",
name="targeting_parameters",
field=models.JSONField(
blank=True,
null=True,
validators=[adserver.validators.TargetingParametersValidator()],
verbose_name="Targeting parameters",
),
),
migrations.AlterField(
model_name="historicalflight",
name="traffic_cap",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[adserver.validators.TrafficFillValidator()],
verbose_name="Traffic cap",
),
),
migrations.AlterField(
model_name="historicalflight",
name="traffic_fill",
field=models.JSONField(
blank=True,
default=None,
null=True,
validators=[adserver.validators.TrafficFillValidator()],
verbose_name="Traffic fill",
),
),
migrations.AlterField(
model_name="offer",
name="keywords",
field=models.JSONField(
blank=True, null=True, verbose_name="Keyword targeting for this view"
),
),
migrations.AlterField(
model_name="region",
name="prices",
field=models.JSONField(
blank=True,
help_text="Topic pricing matrix for this region",
null=True,
validators=[adserver.validators.TopicPricingValidator()],
verbose_name="Topic prices",
),
),
migrations.AlterField(
model_name="view",
name="keywords",
field=models.JSONField(
blank=True, null=True, verbose_name="Keyword targeting for this view"
),
),
]
13 changes: 7 additions & 6 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from django_countries.fields import CountryField
from django_extensions.db.models import TimeStampedModel
from djstripe.enums import InvoiceStatus
from jsonfield import JSONField
from simple_history.models import HistoricalRecords
from user_agents import parse

Expand Down Expand Up @@ -195,7 +194,7 @@ class Region(TimeStampedModel, models.Model):
help_text=_("Whether advertisers can select this region for new flights"),
)

prices = JSONField(
prices = models.JSONField(
_("Topic prices"),
blank=True,
null=True,
Expand Down Expand Up @@ -831,7 +830,7 @@ class Flight(TimeStampedModel, IndestructibleModel):
Campaign, related_name="flights", on_delete=models.PROTECT
)

targeting_parameters = JSONField(
targeting_parameters = models.JSONField(
_("Targeting parameters"),
blank=True,
null=True,
Expand Down Expand Up @@ -866,7 +865,7 @@ class Flight(TimeStampedModel, IndestructibleModel):
# "countries": {"US": 0.1, "CA": 0.05, "DE": 0.05},
# "regions": {"us-ca": 0.25, "eu": 0.5},
# }
traffic_fill = JSONField(
traffic_fill = models.JSONField(
_("Traffic fill"),
blank=True,
null=True,
Expand All @@ -877,7 +876,7 @@ class Flight(TimeStampedModel, IndestructibleModel):
# If set, any publisher, country, or region whose `traffic_fill` exceeds the cap
# will not be eligible to show on this campaign until they're below the cap.
# Format is the same as `traffic_fill` but this is set manually
traffic_cap = JSONField(
traffic_cap = models.JSONField(
_("Traffic cap"),
blank=True,
null=True,
Expand Down Expand Up @@ -2540,7 +2539,9 @@ class AdBase(TimeStampedModel, IndestructibleModel):
)

# Client data
keywords = JSONField(_("Keyword targeting for this view"), blank=True, null=True)
keywords = models.JSONField(
_("Keyword targeting for this view"), blank=True, null=True
)
div_id = models.CharField(
_("Div id"), blank=True, null=True, max_length=DIV_MAXLENGTH
)
Expand Down
19 changes: 3 additions & 16 deletions requirements/analyzer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile analyzer.in
# pip-compile --output-file=analyzer.txt analyzer.in
#
babel==2.15.0
# via courlan
Expand Down Expand Up @@ -32,9 +32,7 @@ click==8.1.7
# nltk
# typer
confection==0.1.5
# via
# thinc
# weasel
# via thinc
courlan==1.2.0
# via trafilatura
cymem==2.0.8
Expand All @@ -53,7 +51,6 @@ filelock==3.15.4
# huggingface-hub
# torch
# transformers
# triton
floret==0.10.5
# via textacy
fsspec==2024.6.1
Expand Down Expand Up @@ -87,7 +84,7 @@ langdetect==1.0.9
# via -r analyzer.in
language-data==1.2.0
# via langcodes
lxml[html-clean,html_clean]==5.2.2
lxml[html_clean]==5.2.2
# via
# -r analyzer.in
# htmldate
Expand Down Expand Up @@ -135,7 +132,6 @@ packaging==24.1
# spacy
# thinc
# transformers
# weasel
pathlib-abc==0.1.1
# via pathy
pathy==0.11.0
Expand All @@ -153,7 +149,6 @@ pydantic==1.10.17
# confection
# spacy
# thinc
# weasel
pyphen==0.15.0
# via textacy
python-dateutil==2.9.0.post0
Expand All @@ -177,7 +172,6 @@ requests==2.32.3
# spacy
# textacy
# transformers
# weasel
scikit-learn==1.5.1
# via
# sentence-transformers
Expand All @@ -199,7 +193,6 @@ smart-open==6.4.0
# via
# pathy
# spacy
# weasel
soupsieve==2.5
# via beautifulsoup4
spacy==3.4.4
Expand All @@ -222,7 +215,6 @@ srsly==2.4.8
# spacy
# spacy-transformers
# thinc
# weasel
sympy==1.13.0
# via torch
textacy==0.13.0
Expand Down Expand Up @@ -258,16 +250,12 @@ transformers==4.26.1
# via
# sentence-transformers
# spacy-transformers
triton==2.3.1
# via torch
typer==0.7.0
# via
# pathy
# spacy
# weasel
typing-extensions==4.12.2
# via
# cloudpathlib
# huggingface-hub
# pydantic
# torch
Expand All @@ -283,7 +271,6 @@ wasabi==0.10.1
# via
# spacy
# thinc
# weasel

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 0 additions & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ IP2Proxy
# Countries helper used in ad targeting
django-countries

jsonfield
ericholscher marked this conversation as resolved.
Show resolved Hide resolved
bleach

# Security features
Expand Down
5 changes: 1 addition & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile base.in
# pip-compile --output-file=base.txt base.in
#
aiohttp==3.9.5
# via geoip2
Expand Down Expand Up @@ -59,7 +59,6 @@ django==5.0.8
# django-simple-history
# django-slack
# djangorestframework
# jsonfield
django-allauth==0.63.6
# via -r base.in
django-cors-headers==4.4.0
Expand Down Expand Up @@ -98,8 +97,6 @@ idna==3.7
# yarl
ip2proxy==3.4.0
# via -r base.in
jsonfield==3.1.0
# via -r base.in
kombu==5.3.7
# via celery
maxminddb==2.6.2
Expand Down
5 changes: 1 addition & 4 deletions requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile development.in
# pip-compile --output-file=development.txt development.in
#
aiohttp==3.9.5
# via geoip2
Expand Down Expand Up @@ -92,7 +92,6 @@ django==5.0.8
# django-simple-history
# django-slack
# djangorestframework
# jsonfield
django-allauth==0.63.6
# via -r base.in
django-cors-headers==4.4.0
Expand Down Expand Up @@ -174,8 +173,6 @@ jedi==0.19.1
# via ipython
jinja2==3.1.4
# via sphinx
jsonfield==3.1.0
# via -r base.in
kombu==5.3.7
# via celery
markupsafe==2.1.5
Expand Down
Loading
Loading