feat(poll): enforce active respondent uniqueness

This commit is contained in:
2026-07-22 02:54:09 +02:00
parent e2e816cb21
commit cac7733bee
3 changed files with 321 additions and 0 deletions
+12
View File
@@ -99,6 +99,18 @@ class PollResponse(Base, TimestampMixin):
__table_args__ = (
Index("ix_poll_responses_poll_submitted", "poll_id", "submitted_at"),
Index("ix_poll_responses_poll_respondent", "poll_id", "respondent_id"),
Index(
"uq_poll_responses_active_respondent",
"poll_id",
"respondent_id",
unique=True,
sqlite_where=text(
"deleted_at IS NULL AND respondent_id IS NOT NULL"
),
postgresql_where=text(
"deleted_at IS NULL AND respondent_id IS NOT NULL"
),
),
Index("ix_poll_responses_tenant_poll", "tenant_id", "poll_id"),
)