Skip to content

Commit

Permalink
feat: utilize non-distinct nulls in subscription index
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Dec 11, 2024
1 parent 634f30f commit b7a9ba9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 5.1.4 on 2024-12-11 11:43

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0013_bot_notifications"),
("trans", "0025_alter_announcement_notify"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterUniqueTogether(
name="subscription",
unique_together=set(),
),
migrations.AddConstraint(
model_name="subscription",
constraint=models.UniqueConstraint(
fields=("notification", "scope", "project", "component", "user"),
name="accounts_subscription_notification_unique",
nulls_distinct=False,
),
),
]
8 changes: 7 additions & 1 deletion weblate/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,15 @@ class Subscription(models.Model):
objects = SubscriptionQuerySet.as_manager()

class Meta:
unique_together = [("notification", "scope", "project", "component", "user")]
verbose_name = "Notification subscription"
verbose_name_plural = "Notification subscriptions"
constraints = [
models.UniqueConstraint(
name="accounts_subscription_notification_unique",
fields=("notification", "scope", "project", "component", "user"),
nulls_distinct=False,
),
]

def __str__(self) -> str:
return f"{self.user.username}:{self.get_scope_display()},{self.get_notification_display()} ({self.project},{self.component})"
Expand Down

0 comments on commit b7a9ba9

Please sign in to comment.