Browse Source

chore(hybridcloud) Remove TeamAvatar & ProjectAvatar from django state (#68542)

These models were never used and not having them will reduce complexity
and junk code. Not having these models also makes changes to other
Avatars easier.

Refs #68364

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Mark Story 11 months ago
parent
commit
b59e927f57

+ 0 - 66
fixtures/backup/model_dependencies/detailed.json

@@ -4143,39 +4143,6 @@
     "table_name": "sentry_projectartifactbundle",
     "uniques": []
   },
-  "sentry.projectavatar": {
-    "dangling": false,
-    "foreign_keys": {
-      "file_id": {
-        "kind": "ImplicitForeignKey",
-        "model": "sentry.file",
-        "nullable": true
-      },
-      "project": {
-        "kind": "FlexibleForeignKey",
-        "model": "sentry.project",
-        "nullable": false
-      }
-    },
-    "model": "sentry.projectavatar",
-    "relocation_dependencies": [],
-    "relocation_scope": "Excluded",
-    "silos": [
-      "Region"
-    ],
-    "table_name": "sentry_projectavatar",
-    "uniques": [
-      [
-        "file_id"
-      ],
-      [
-        "ident"
-      ],
-      [
-        "project"
-      ]
-    ]
-  },
   "sentry.projectbookmark": {
     "dangling": false,
     "foreign_keys": {
@@ -5904,39 +5871,6 @@
       ]
     ]
   },
-  "sentry.teamavatar": {
-    "dangling": false,
-    "foreign_keys": {
-      "file_id": {
-        "kind": "ImplicitForeignKey",
-        "model": "sentry.file",
-        "nullable": true
-      },
-      "team": {
-        "kind": "FlexibleForeignKey",
-        "model": "sentry.team",
-        "nullable": false
-      }
-    },
-    "model": "sentry.teamavatar",
-    "relocation_dependencies": [],
-    "relocation_scope": "Excluded",
-    "silos": [
-      "Region"
-    ],
-    "table_name": "sentry_teamavatar",
-    "uniques": [
-      [
-        "file_id"
-      ],
-      [
-        "ident"
-      ],
-      [
-        "team"
-      ]
-    ]
-  },
   "sentry.teamkeytransaction": {
     "dangling": false,
     "foreign_keys": {

+ 0 - 8
fixtures/backup/model_dependencies/flat.json

@@ -572,10 +572,6 @@
     "sentry.organization",
     "sentry.project"
   ],
-  "sentry.projectavatar": [
-    "sentry.file",
-    "sentry.project"
-  ],
   "sentry.projectbookmark": [
     "sentry.project",
     "sentry.user"
@@ -813,10 +809,6 @@
   "sentry.team": [
     "sentry.organization"
   ],
-  "sentry.teamavatar": [
-    "sentry.file",
-    "sentry.team"
-  ],
   "sentry.teamkeytransaction": [
     "sentry.organization",
     "sentry.projectteam"

+ 0 - 2
fixtures/backup/model_dependencies/sorted.json

@@ -125,7 +125,6 @@
   "sentry.useremail",
   "sentry.useravatar",
   "sentry.teamkeytransaction",
-  "sentry.teamavatar",
   "sentry.snubaquery",
   "sentry.sentryapp",
   "sentry.rule",
@@ -143,7 +142,6 @@
   "sentry.querysubscription",
   "sentry.pullrequest",
   "sentry.projectdebugfile",
-  "sentry.projectavatar",
   "sentry.projectartifactbundle",
   "sentry.proguardartifactrelease",
   "sentry.platformexternalissue",

+ 0 - 2
fixtures/backup/model_dependencies/truncate.json

@@ -125,7 +125,6 @@
   "sentry_useremail",
   "sentry_useravatar",
   "sentry_performanceteamkeytransaction",
-  "sentry_teamavatar",
   "sentry_snubaquery",
   "sentry_sentryapp",
   "sentry_rule",
@@ -143,7 +142,6 @@
   "sentry_querysubscription",
   "sentry_pull_request",
   "sentry_projectdsymfile",
-  "sentry_projectavatar",
   "sentry_projectartifactbundle",
   "sentry_proguardartifactrelease",
   "sentry_platformexternalissue",

+ 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: 0690_remove_project_team_avatar
+sentry: 0691_remove_project_team_avatar_model
 social_auth: 0002_default_auto_field

+ 43 - 0
src/sentry/migrations/0691_remove_project_team_avatar_model.py

@@ -0,0 +1,43 @@
+# Generated by Django 5.0.3 on 2024-04-09 17:17
+
+from django.db import migrations
+
+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.
+    # 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 post deployment:
+    # - Large data migrations. Typically we want these to be run manually 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
+    #   run this outside deployments so that we don't block them. Note that while adding an index
+    #   is a schema change, it's completely safe to run the operation after the code has deployed.
+    # Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
+
+    is_post_deployment = False
+
+    dependencies = [
+        ("sentry", "0690_remove_project_team_avatar"),
+    ]
+
+    operations = [
+        migrations.SeparateDatabaseAndState(
+            state_operations=[
+                migrations.RemoveField(
+                    model_name="teamavatar",
+                    name="team",
+                ),
+                migrations.DeleteModel(
+                    name="ProjectAvatar",
+                ),
+                migrations.DeleteModel(
+                    name="TeamAvatar",
+                ),
+            ],
+            database_operations=[],
+        )
+    ]

+ 0 - 4
src/sentry/models/avatars/__init__.py

@@ -2,9 +2,7 @@ from .base import AvatarBase
 from .control_base import ControlAvatarBase
 from .doc_integration_avatar import DocIntegrationAvatar
 from .organization_avatar import OrganizationAvatar
-from .project_avatar import ProjectAvatar
 from .sentry_app_avatar import SentryAppAvatar
-from .team_avatar import TeamAvatar
 from .user_avatar import UserAvatar
 
 __all__ = (
@@ -12,8 +10,6 @@ __all__ = (
     "ControlAvatarBase",
     "DocIntegrationAvatar",
     "OrganizationAvatar",
-    "ProjectAvatar",
     "SentryAppAvatar",
-    "TeamAvatar",
     "UserAvatar",
 )

+ 0 - 31
src/sentry/models/avatars/project_avatar.py

@@ -1,31 +0,0 @@
-from __future__ import annotations
-
-from django.db import models
-
-from sentry.db.models import FlexibleForeignKey, region_silo_only_model
-
-from . import AvatarBase
-
-
-@region_silo_only_model
-class ProjectAvatar(AvatarBase):
-    """
-    A ProjectAvatar associates a Project with their avatar photo File
-    and contains their preferences for avatar type.
-    """
-
-    AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"))
-
-    FILE_TYPE = "avatar.file"
-
-    project = FlexibleForeignKey(
-        "sentry.Project", unique=True, related_name="avatar", db_constraint=False
-    )
-    avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)
-
-    class Meta:
-        app_label = "sentry"
-        db_table = "sentry_projectavatar"
-
-    def get_cache_key(self, size):
-        return f"project_avatar:{self.project_id}:{size}"

+ 0 - 31
src/sentry/models/avatars/team_avatar.py

@@ -1,31 +0,0 @@
-from __future__ import annotations
-
-from django.db import models
-
-from sentry.db.models import FlexibleForeignKey, region_silo_only_model
-
-from . import AvatarBase
-
-
-@region_silo_only_model
-class TeamAvatar(AvatarBase):
-    """
-    A TeamAvatar associates a Team with their avatar photo File
-    and contains their preferences for avatar type.
-    """
-
-    AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"))
-
-    FILE_TYPE = "avatar.file"
-
-    team = FlexibleForeignKey(
-        "sentry.Team", unique=True, related_name="avatar", db_constraint=False
-    )
-    avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)
-
-    class Meta:
-        app_label = "sentry"
-        db_table = "sentry_teamavatar"
-
-    def get_cache_key(self, size):
-        return f"team_avatar:{self.team_id}:{size}"

+ 1 - 13
tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap

@@ -1,5 +1,5 @@
 ---
-created: '2024-04-09T21:58:14.348228+00:00'
+created: '2024-04-10T14:45:05.473571+00:00'
 creator: sentry
 source: tests/sentry/backup/test_comparators.py
 ---
@@ -1037,12 +1037,6 @@ source: tests/sentry/backup/test_comparators.py
     - organization_id
     - project_id
   model_name: sentry.projectartifactbundle
-- comparators:
-  - class: ForeignKeyComparator
-    fields:
-    - file_id
-    - project
-  model_name: sentry.projectavatar
 - comparators:
   - class: ForeignKeyComparator
     fields:
@@ -1486,12 +1480,6 @@ source: tests/sentry/backup/test_comparators.py
     fields:
     - organization
   model_name: sentry.team
-- comparators:
-  - class: ForeignKeyComparator
-    fields:
-    - file_id
-    - team
-  model_name: sentry.teamavatar
 - comparators:
   - class: ForeignKeyComparator
     fields: