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 5 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
4 changes: 3 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 All @@ -62,3 +61,6 @@ PyJWT

# CORS headers
django-cors-headers

# Deprecated, but still used in migrations
jsonfield
Loading