Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🗃️ Record why a poll was closed with closedReason (#2583)

Luke Vella8e55eb6c565f
diff --git a/apps/web/src/app/api/house-keeping/[...method]/route.ts b/apps/web/src/app/api/house-keeping/[...method]/route.ts
index d1dfad924..3104d7294 100644
--- a/apps/web/src/app/api/house-keeping/[...method]/route.ts
+++ b/apps/web/src/app/api/house-keeping/[...method]/route.ts
@@ -99,7 +99,7 @@ app.get("/delete-inactive-polls", async (c) => {
app.get("/auto-close-polls", async (c) => {
const closed = await prisma.$executeRaw`
UPDATE polls p
- SET status = 'closed'
+ SET status = 'closed', closed_reason = 'auto'
WHERE p.status = 'open'
AND p.deleted = false
AND EXISTS (SELECT 1 FROM options o WHERE o.poll_id = p.id)
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index ca7c1f26f..024bf6ce4 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -378,22 +378,15 @@ export const polls = router({
}
}) ?? [];
- // Reopen a closed poll when new future dates are added, but only if
- // every pre-existing option had already ended — that state matches an
- // auto-close, whereas a manual pause with future dates stays paused.
+ // Reopen an auto-closed poll when new future dates are added. Manually
+ // closed polls stay closed — that was the organizer's decision.
let reopen = false;
if (newOptions.some(optionEndsInFuture)) {
const poll = await tx.poll.findUnique({
where: { id: pollId },
- select: { status: true },
+ select: { status: true, closedReason: true },
});
- if (poll?.status === "closed") {
- const existingOptions = await tx.option.findMany({
- where: { pollId },
- select: { startTime: true, duration: true },
- });
- reopen = !existingOptions.some(optionEndsInFuture);
- }
+ reopen = poll?.status === "closed" && poll.closedReason === "auto";
}
if (input.optionsToDelete && input.optionsToDelete.length > 0) {
@@ -444,7 +437,7 @@ export const polls = router({
disableComments: input.disableComments,
requireParticipantEmail: input.requireParticipantEmail,
kind,
- status: reopen ? "open" : undefined,
+ ...(reopen ? { status: "open" as const, closedReason: null } : {}),
},
});
});
@@ -940,6 +933,7 @@ export const polls = router({
},
data: {
status: "scheduled",
+ closedReason: null,
scheduledEventId: event.id,
},
});
@@ -1108,6 +1102,7 @@ export const polls = router({
},
data: {
status: "open",
+ closedReason: null,
},
});
@@ -1151,6 +1146,7 @@ export const polls = router({
},
data: {
status: "closed",
+ closedReason: "manual",
},
});
diff --git a/packages/database/prisma/migrations/20260710092341_add_poll_closed_reason/migration.sql b/packages/database/prisma/migrations/20260710092341_add_poll_closed_reason/migration.sql
new file mode 100644
index 000000000..1f7c75bca
--- /dev/null
+++ b/packages/database/prisma/migrations/20260710092341_add_poll_closed_reason/migration.sql
@@ -0,0 +1,22 @@
+-- CreateEnum
+CREATE TYPE "poll_closed_reason" AS ENUM ('auto', 'manual');
+
+-- AlterTable
+ALTER TABLE "polls" ADD COLUMN "closed_reason" "poll_closed_reason";
+
+-- Backfill: a closed poll whose options have all ended (the auto-close-polls
+-- condition: end = start + duration, all-day options counted as 24h) is
+-- attributed to auto-close; a closed poll with a future option can only have
+-- been closed by the organizer, since the cron never closes those.
+UPDATE polls p
+SET closed_reason = CASE
+ WHEN EXISTS (
+ SELECT 1 FROM options o
+ WHERE o.poll_id = p.id
+ AND o.start_time + (CASE WHEN o.duration_minutes = 0
+ THEN interval '24 hours'
+ ELSE make_interval(mins => o.duration_minutes) END) > (now() AT TIME ZONE 'UTC')
+ ) THEN 'manual'::poll_closed_reason
+ ELSE 'auto'::poll_closed_reason
+END
+WHERE p.status = 'closed';
diff --git a/packages/database/prisma/models/poll.prisma b/packages/database/prisma/models/poll.prisma
index 66d35bb2d..9e81bfbe9 100644
--- a/packages/database/prisma/models/poll.prisma
+++ b/packages/database/prisma/models/poll.prisma
@@ -22,29 +22,37 @@ enum PollKind {
@@map("poll_kind")
}
+enum PollClosedReason {
+ auto
+ manual
+
+ @@map("poll_closed_reason")
+}
+
model Poll {
- id String @id @unique @map("id")
- createdAt DateTime @default(now()) @map("created_at")
- updatedAt DateTime @updatedAt @map("updated_at")
+ id String @id @unique @map("id")
+ createdAt DateTime @default(now()) @map("created_at")
+ updatedAt DateTime @updatedAt @map("updated_at")
deadline DateTime?
title String
description String?
location String?
- userId String? @map("user_id")
- timeZone String? @map("time_zone")
- status PollStatus @default(open)
- kind PollKind @default(date)
- deleted Boolean @default(false)
- deletedAt DateTime? @map("deleted_at")
- participantUrlId String @unique @map("participant_url_id")
- adminUrlId String @unique @map("admin_url_id")
- eventId String? @unique @map("event_id")
- scheduledEventId String? @map("scheduled_event_id")
- hideParticipants Boolean @default(false) @map("hide_participants")
- hideScores Boolean @default(false) @map("hide_scores")
- disableComments Boolean @default(false) @map("disable_comments")
- requireParticipantEmail Boolean @default(false) @map("require_participant_email")
- muted Boolean @default(false)
+ userId String? @map("user_id")
+ timeZone String? @map("time_zone")
+ status PollStatus @default(open)
+ closedReason PollClosedReason? @map("closed_reason")
+ kind PollKind @default(date)
+ deleted Boolean @default(false)
+ deletedAt DateTime? @map("deleted_at")
+ participantUrlId String @unique @map("participant_url_id")
+ adminUrlId String @unique @map("admin_url_id")
+ eventId String? @unique @map("event_id")
+ scheduledEventId String? @map("scheduled_event_id")
+ hideParticipants Boolean @default(false) @map("hide_participants")
+ hideScores Boolean @default(false) @map("hide_scores")
+ disableComments Boolean @default(false) @map("disable_comments")
+ requireParticipantEmail Boolean @default(false) @map("require_participant_email")
+ muted Boolean @default(false)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
scheduledEvent ScheduledEvent? @relation(fields: [scheduledEventId], references: [id], onDelete: SetNull)
diff --git a/packages/database/prisma/seed.ts b/packages/database/prisma/seed.ts
index 64f4523c9..254ba824c 100644
--- a/packages/database/prisma/seed.ts
+++ b/packages/database/prisma/seed.ts
@@ -98,6 +98,7 @@ async function main() {
description: poll.description,
location: poll.location,
status: poll.status,
+ closedReason: poll.closedReason,
timeZone: poll.timeZone,
deadline: poll.deadline ? new Date(poll.deadline) : undefined,
userId: poll.userId,
diff --git a/packages/database/prisma/seed/data.ts b/packages/database/prisma/seed/data.ts
index 65c11e9c9..c6960292d 100644
--- a/packages/database/prisma/seed/data.ts
+++ b/packages/database/prisma/seed/data.ts
@@ -1,4 +1,5 @@
import type {
+ PollClosedReason,
PollStatus,
ScheduledEventInviteStatus,
ScheduledEventStatus,
@@ -86,6 +87,7 @@ export type PollDef = {
description?: string;
location?: string;
status: PollStatus;
+ closedReason?: PollClosedReason;
timeZone?: string;
deadline?: string;
userId: string;
@@ -215,6 +217,7 @@ const personalPolls: PollDef[] = [
title: "Dinner with the Johnsons",
description: "Finding a good evening for dinner at their place.",
status: "closed",
+ closedReason: "auto",
timeZone: "America/New_York",
userId: "user-1",
spaceId: "space-1",
@@ -526,6 +529,7 @@ const acmePolls: PollDef[] = [
description: "Reflecting on Sprint 14. What went well, what didn't.",
location: "Zoom",
status: "closed",
+ closedReason: "manual",
timeZone: "America/New_York",
userId: "user-3",
spaceId: "space-2",
@@ -701,6 +705,7 @@ const acmePolls: PollDef[] = [
description:
"Our current 9am ET standup doesn't work for everyone. Let's find a better slot.",
status: "closed",
+ closedReason: "auto",
timeZone: "America/New_York",
userId: "user-3",
spaceId: "space-2",