Skip to content

Commit

Permalink
Drop FK constraint on media_obj in MediaDecisionThrough, update backf…
Browse files Browse the repository at this point in the history
…illmoderationdecision command (#4530)

* Remove foreign key constraint on media_obj from decision through table

* Create MediaDecisionThrough objects using identifier rather than instance

* On delete DO_NOTHING
  • Loading branch information
stacimc authored Jun 24, 2024
1 parent 50fe56e commit 70d71b3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion api/api/management/commands/backfillmoderationdecision.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def handle(self, *args, **options):
MediaReport.objects.bulk_update(reports_chunk, ["decision"])
MediaDecisionThrough.objects.bulk_create(
[
MediaDecisionThrough(media_obj=report.media_obj, decision=decision)
MediaDecisionThrough(
media_obj_id=report.media_obj_id, decision=decision
)
for report, decision in zip(reports_chunk, decisions)
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.11 on 2024-06-24 17:47

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0066_rename_contentprovider_to_contentsource'),
]

operations = [
migrations.AlterField(
model_name='audiodecisionthrough',
name='media_obj',
field=models.ForeignKey(db_column='identifier', db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='api.audio', to_field='identifier'),
),
migrations.AlterField(
model_name='imagedecisionthrough',
name='media_obj',
field=models.ForeignKey(db_column='identifier', db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='api.image', to_field='identifier'),
),
]
3 changes: 2 additions & 1 deletion api/api/models/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ class AudioDecisionThrough(AbstractMediaDecisionThrough):
media_obj = models.ForeignKey(
Audio,
to_field="identifier",
on_delete=models.CASCADE,
on_delete=models.DO_NOTHING,
db_column="identifier",
db_constraint=False,
)
decision = models.ForeignKey(AudioDecision, on_delete=models.CASCADE)

Expand Down
3 changes: 2 additions & 1 deletion api/api/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ class ImageDecisionThrough(AbstractMediaDecisionThrough):
media_obj = models.ForeignKey(
Image,
to_field="identifier",
on_delete=models.CASCADE,
on_delete=models.DO_NOTHING,
db_column="identifier",
db_constraint=False,
)
decision = models.ForeignKey(ImageDecision, on_delete=models.CASCADE)

Expand Down
3 changes: 2 additions & 1 deletion api/api/models/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,9 @@ class AbstractMediaDecisionThrough(models.Model):
media_obj = models.ForeignKey(
AbstractMedia,
to_field="identifier",
on_delete=models.CASCADE,
on_delete=models.DO_NOTHING,
db_column="identifier",
db_constraint=False,
)
decision = models.ForeignKey(AbstractMediaDecision, on_delete=models.CASCADE)

Expand Down
2 changes: 1 addition & 1 deletion api/latest_migrations/api
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# If you have a merge conflict in this file, it means you need to run:
# manage.py makemigrations --merge
# in order to resolve the conflict between migrations.
0066_contentsource_delete_contentprovider
0067_alter_audiodecisionthrough_media_obj_and_more

0 comments on commit 70d71b3

Please sign in to comment.