chore: create unique constraints for webhook (#6257)

* chore: create unique constraints for webhook

* chore: updated the migration file
This commit is contained in:
Bavisetti Narayan 2024-12-24 21:00:50 +05:30 committed by GitHub
parent 70f72a2b0f
commit 2d9464e841
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 2 deletions

View file

@ -116,7 +116,7 @@ class WebhookSerializer(DynamicBaseSerializer):
class Meta:
model = Webhook
fields = "__all__"
read_only_fields = ["workspace", "secret_key"]
read_only_fields = ["workspace", "secret_key", "deleted_at"]
class WebhookLogSerializer(DynamicBaseSerializer):

View file

@ -109,4 +109,16 @@ class Migration(migrations.Migration):
name="entity_name",
field=models.CharField(max_length=30, verbose_name="Transaction Type"),
),
migrations.AlterUniqueTogether(
name="webhook",
unique_together={("workspace", "url", "deleted_at")},
),
migrations.AddConstraint(
model_name="webhook",
constraint=models.UniqueConstraint(
condition=models.Q(("deleted_at__isnull", True)),
fields=("workspace", "url"),
name="webhook_url_unique_url_when_deleted_at_null",
),
),
]

View file

@ -47,11 +47,18 @@ class Webhook(BaseModel):
return f"{self.workspace.slug} {self.url}"
class Meta:
unique_together = ["workspace", "url"]
unique_together = ["workspace", "url", "deleted_at"]
verbose_name = "Webhook"
verbose_name_plural = "Webhooks"
db_table = "webhooks"
ordering = ("-created_at",)
constraints = [
models.UniqueConstraint(
fields=["workspace", "url"],
condition=models.Q(deleted_at__isnull=True),
name="webhook_url_unique_url_when_deleted_at_null",
)
]
class WebhookLog(BaseModel):