Browse Source

chore(api) Remove Team and Project Avatar models (#68364)

We have never used these models. I removed the API endpoints for these
models a few months back in 6acf1398877fa545e21afa16ef82571796c4d10e I
want to remove these models as it reduces complexity and junk code in
the application/database and makes cleanup work on other avatars easier.
Mark Story 11 months ago
parent
commit
12baaa770b

+ 1 - 1
migrations_lockfile.txt

@@ -9,5 +9,5 @@ feedback: 0004_index_together
 hybridcloud: 0015_apitokenreplica_hashed_token_index
 nodestore: 0002_nodestore_no_dictfield
 replays: 0004_index_together
-sentry: 0689_drop_config_from_cron_checkin
+sentry: 0690_remove_project_team_avatar
 social_auth: 0002_default_auto_field

+ 50 - 0
src/sentry/migrations/0690_remove_project_team_avatar.py

@@ -0,0 +1,50 @@
+# Generated by Django 5.0.3 on 2024-04-05 17:53
+
+import django.db.models.deletion
+from django.db import migrations
+
+import sentry.db.models.fields.foreignkey
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    # This flag is used to mark that a migration shouldn't be automatically run in production. For
+    # the most part, this should only be used for operations where it's safe to run the migration
+    # after your code has deployed. So this should not be used for most operations that alter the
+    # schema of a table.
+    # Here are some things that make sense to mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that they can
+    #   be monitored and not block the deploy for a long period of time while they run.
+    # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = False
+
+    dependencies = [
+        ("sentry", "0689_drop_config_from_cron_checkin"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="projectavatar",
+            name="project",
+            field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                db_constraint=False,
+                on_delete=django.db.models.deletion.CASCADE,
+                related_name="avatar",
+                to="sentry.project",
+                unique=True,
+            ),
+        ),
+        migrations.AlterField(
+            model_name="teamavatar",
+            name="team",
+            field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                db_constraint=False,
+                on_delete=django.db.models.deletion.CASCADE,
+                related_name="avatar",
+                to="sentry.team",
+                unique=True,
+            ),
+        ),
+    ]

+ 1 - 2
src/sentry/models/avatars/base.py

@@ -23,8 +23,7 @@ from sentry.utils.db import atomic_transaction
 
 class AvatarBase(Model):
     """
-    Base class for UserAvatar, OrganizationAvatar, TeamAvatar,
-    SentryAppAvatar, and ProjectAvatar models. Associates those entities with their
+    Base class for UserAvatar, OrganizationAvatar, and SentryAppAvatar models. Associates those entities with their
     avatar preferences/files. If extending this class, ensure the model has avatar_type.
     """
 

+ 3 - 1
src/sentry/models/avatars/project_avatar.py

@@ -18,7 +18,9 @@ class ProjectAvatar(AvatarBase):
 
     FILE_TYPE = "avatar.file"
 
-    project = FlexibleForeignKey("sentry.Project", unique=True, related_name="avatar")
+    project = FlexibleForeignKey(
+        "sentry.Project", unique=True, related_name="avatar", db_constraint=False
+    )
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)
 
     class Meta:

+ 3 - 1
src/sentry/models/avatars/team_avatar.py

@@ -18,7 +18,9 @@ class TeamAvatar(AvatarBase):
 
     FILE_TYPE = "avatar.file"
 
-    team = FlexibleForeignKey("sentry.Team", unique=True, related_name="avatar")
+    team = FlexibleForeignKey(
+        "sentry.Team", unique=True, related_name="avatar", db_constraint=False
+    )
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)
 
     class Meta: