models: Fix incorrect on_delete=CASCADE values for deleted streams.

In theory, we never delete streams, but if we did delete the
notifications stream for a realm, we certainly shouldn't delete the
realm.
This commit is contained in:
Tim Abbott 2021-04-29 12:30:25 -07:00 committed by Tim Abbott
parent 37b265495b
commit 18595fac58
2 changed files with 60 additions and 4 deletions

View File

@ -0,0 +1,56 @@
# Generated by Django 3.2 on 2021-05-07 01:00
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("zerver", "0323_show_starred_message_counts"),
]
operations = [
migrations.AlterField(
model_name="realm",
name="notifications_stream",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="zerver.stream",
),
),
migrations.AlterField(
model_name="realm",
name="signup_notifications_stream",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="zerver.stream",
),
),
migrations.AlterField(
model_name="userprofile",
name="default_events_register_stream",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="zerver.stream",
),
),
migrations.AlterField(
model_name="userprofile",
name="default_sending_stream",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="zerver.stream",
),
),
]

View File

@ -375,14 +375,14 @@ class Realm(models.Model):
related_name="+",
null=True,
blank=True,
on_delete=CASCADE,
on_delete=models.SET_NULL,
)
signup_notifications_stream: Optional["Stream"] = models.ForeignKey(
"Stream",
related_name="+",
null=True,
blank=True,
on_delete=CASCADE,
on_delete=models.SET_NULL,
)
MESSAGE_RETENTION_SPECIAL_VALUES_MAP = {
@ -1266,13 +1266,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
"zerver.Stream",
null=True,
related_name="+",
on_delete=CASCADE,
on_delete=models.SET_NULL,
)
default_events_register_stream: Optional["Stream"] = models.ForeignKey(
"zerver.Stream",
null=True,
related_name="+",
on_delete=CASCADE,
on_delete=models.SET_NULL,
)
default_all_public_streams: bool = models.BooleanField(default=False)