Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Drop FK constraint on media_obj in MediaDecisionThrough, update backfillmoderationdecision command (#4530)

Staci Mullins70d71b310724
diff --git a/api/api/management/commands/backfillmoderationdecision.py b/api/api/management/commands/backfillmoderationdecision.py
index 2b3598a3a..e7d704e6d 100644
--- a/api/api/management/commands/backfillmoderationdecision.py
+++ b/api/api/management/commands/backfillmoderationdecision.py
@@ -94,7 +94,9 @@ class Command(BaseCommand):
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)
]
)
diff --git a/api/api/migrations/0067_alter_audiodecisionthrough_media_obj_and_more.py b/api/api/migrations/0067_alter_audiodecisionthrough_media_obj_and_more.py
new file mode 100644
index 000000000..c052f702e
--- /dev/null
+++ b/api/api/migrations/0067_alter_audiodecisionthrough_media_obj_and_more.py
@@ -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'),
+ ),
+ ]
diff --git a/api/api/models/audio.py b/api/api/models/audio.py
index f1863ea40..3f7a4637b 100644
--- a/api/api/models/audio.py
+++ b/api/api/models/audio.py
@@ -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)
diff --git a/api/api/models/image.py b/api/api/models/image.py
index 3d361d473..873f7ad3a 100644
--- a/api/api/models/image.py
+++ b/api/api/models/image.py
@@ -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)
diff --git a/api/api/models/media.py b/api/api/models/media.py
index 86352967b..2bccfea11 100644
--- a/api/api/models/media.py
+++ b/api/api/models/media.py
@@ -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)
diff --git a/api/latest_migrations/api b/api/latest_migrations/api
index 2f6c01764..080816ff3 100644
--- a/api/latest_migrations/api
+++ b/api/latest_migrations/api
@@ -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