Browse Source

feat(crons): Remove slug null=True (#45276)

Evan Purkhiser 2 years ago
parent
commit
177ad33167

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0367_migrate_monitor_guid_to_slug
+sentry: 0368_monitor_remove_slug_nullable
 social_auth: 0001_initial

+ 31 - 0
src/sentry/migrations/0368_monitor_remove_slug_nullable.py

@@ -0,0 +1,31 @@
+# Generated by Django 2.2.28 on 2023-02-28 02:05
+
+from django.db import migrations, models
+
+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", "0367_migrate_monitor_guid_to_slug"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="monitor",
+            name="slug",
+            field=models.SlugField(),
+        ),
+    ]

+ 2 - 2
src/sentry/models/monitor.py

@@ -125,7 +125,7 @@ class Monitor(Model):
     __include_in_export__ = True
 
     guid = UUIDField(unique=True, auto_add=True)
-    slug = models.SlugField(null=True)
+    slug = models.SlugField()
     organization_id = BoundedBigIntegerField(db_index=True)
     project_id = BoundedBigIntegerField(db_index=True)
     name = models.CharField(max_length=128)
@@ -155,7 +155,7 @@ class Monitor(Model):
         # NOTE: We ONLY set a slug while saving when creating a new monitor and
         # the slug has not been set. Otherwise existing monitors without slugs
         # would have their guids changed
-        if self._state.adding is True and self.slug is None:
+        if self._state.adding is True and self.slug == "":
             self.guid = uuid4()
             self.slug = str(self.guid)
         return super().save(*args, **kwargs)

+ 1 - 1
tests/sentry/models/test_monitor.py

@@ -202,7 +202,7 @@ class MonitorTestCase(TestCase):
         original_monitor_guid = monitor.guid
 
         # Simulate existing monitors entries that don't have a slug set
-        monitor.slug = None
+        monitor.slug = ""
         monitor.name = "New name"
         monitor.save()