Skip to content

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

8.1 KB
Raw Blame
enum ParticipantVisibility {
  full
  scoresOnly
  limited

  @@map("participant_visibility")
}

enum PollStatus {
  open
  closed
  scheduled
  canceled

  @@map("poll_status")
}

enum PollKind {
  date
  time

  @@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")
  deadline                DateTime?
  title                   String
  description             String?
  location                String?
  /// What the organizer asked for: a provider to mint a link with at
  /// finalize ("zoom" | "meet" | "teams" | "webex"), or a link they pasted
  /// themselves.
  conferencing            Json?
  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")
  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(true) @map("disable_comments")
  requireParticipantEmail Boolean           @default(false) @map("require_participant_email")
  /// Whether participants may cast the tentative "if need be" vote. Positive
  /// flag so a future vote-type expansion adds columns rather than inverting a
  /// negative. Turning it off only blocks new tentative votes; existing ones
  /// are kept and stay visible.
  allowTentativeVotes     Boolean           @default(true) @map("allow_tentative_votes")
  muted                   Boolean           @default(false)

  user           User?           @relation(fields: [userId], references: [id], onDelete: Cascade)
  scheduledEvent ScheduledEvent? @relation(fields: [scheduledEventId], references: [id], onDelete: SetNull)
  options        Option[]
  participants   Participant[]
  comments       Comment[]
  votes          Vote[]
  invites        PollInvite[]
  activities     PollActivity[]
  space          Space?          @relation(fields: [spaceId], references: [id], onDelete: SetNull)
  spaceId        String?         @map("space_id")

  @@index([spaceId])
  @@index([userId])
  @@map("polls")
}

model Participant {
  id        String    @id @default(cuid())
  name      String
  email     String?
  note      String?
  /// Per response edit link: grants edit access to this response without a session. App minted at creation, CSPRNG alphanumeric ≥32 chars (nanoid customAlphabet — url safe with no linkifier edge cases, unlike base64url); never a DB default so a code path that forgets to mint fails loudly. A response created through an emailed invite takes the invite's token. Rows that predate minting were backfilled with gen_random_uuid() hex
  token     String    @unique
  userId    String?   @map("user_id")
  pollId    String    @map("poll_id")
  locale    String?
  timeZone  String?   @map("time_zone")
  createdAt DateTime  @default(now()) @map("created_at")
  updatedAt DateTime? @updatedAt @map("updated_at")

  votes  Vote[]
  invite PollInvite?

  poll Poll  @relation(fields: [pollId], references: [id], onDelete: Cascade)
  user User? @relation(fields: [userId], references: [id], onDelete: SetNull)

  @@index([pollId], type: Hash)
  @@index([userId])
  @@map("participants")
}

model PollInvite {
  id     String @id @default(cuid())
  pollId String @map("poll_id")
  email  String @db.Citext
  /// Per invitee link. App minted, CSPRNG alphanumeric ≥32 chars (nanoid customAlphabet) — no schema default, so forgetting to mint fails loudly. Rotated on reactivation so a revoked (possibly leaked) token never regains access
  token  String @unique

  openedAt   DateTime? @map("opened_at")
  remindedAt DateTime? @map("reminded_at")
  /// Revocation is always explicit: set when the host removes a pending invite, never as a side effect of close, schedule or reopen. Deleting a response instead hard deletes the participant, so the SetNull FK clears participantId and reverts the invite to pending with its token intact — the token the deleted response held is freed with it, so the next response through the same link can take it again. Cleared only by re-inviting (reactivation), which also rotates the token
  revokedAt  DateTime? @map("revoked_at")

  /// Conversion join, merges invite history into the response timeline. Set only when the invitee responds via their token: a typed email is unverified, so a generic link response never claims an invite
  participantId String? @unique @map("participant_id")

  createdAt DateTime @default(now()) @map("created_at")
  updatedAt DateTime @updatedAt @map("updated_at")

  poll        Poll         @relation(fields: [pollId], references: [id], onDelete: Cascade)
  participant Participant? @relation(fields: [participantId], references: [id], onDelete: SetNull)

  @@unique([pollId, email])
  @@map("poll_invites")
}

model PollActivity {
  id     String @id @default(cuid())
  pollId String @map("poll_id")
  /// Validated by a zod union in the feature, not a DB enum: the activity vocabulary grows without migrations
  type   String

  /// Subject ids are soft references (no FKs): activity must outlive its subjects — including account deletion — so refs persist as identity and the payload carries the display snapshot; whether a ref still resolves is the renderer's question
  userId        String? @map("user_id")
  participantId String? @map("participant_id")
  inviteId      String? @map("invite_id")
  optionId      String? @map("option_id")
  payload       Json    @default("{}")

  createdAt DateTime @default(now()) @map("created_at")

  poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)

  @@index([pollId, createdAt(sort: Desc)])
  @@index([pollId, participantId])
  @@index([pollId, optionId])
  @@index([pollId, inviteId])
  @@index([userId])
  @@map("poll_activities")
}

model Option {
  id        String   @id @default(cuid())
  startTime DateTime @map("start_time") @db.Timestamp(0)
  duration  Int      @default(0) @map("duration_minutes")
  pollId    String   @map("poll_id")
  createdAt DateTime @default(now()) @map("created_at")

  votes Vote[]

  poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)

  @@index([pollId], type: Hash)
  @@map("options")
}

enum VoteType {
  yes
  no
  ifNeedBe

  @@map("vote_type")
}

model Vote {
  id            String    @id @default(cuid())
  participantId String    @map("participant_id")
  optionId      String    @map("option_id")
  pollId        String    @map("poll_id")
  type          VoteType  @default(yes)
  createdAt     DateTime  @default(now()) @map("created_at")
  updatedAt     DateTime? @updatedAt @map("updated_at")

  participant Participant @relation(fields: [participantId], references: [id], onDelete: Cascade)
  option      Option      @relation(fields: [optionId], references: [id], onDelete: Cascade)
  poll        Poll        @relation(fields: [pollId], references: [id], onDelete: Cascade)

  @@index([pollId], type: Hash)
  @@index([participantId], type: Hash)
  @@index([optionId], type: Hash)
  @@map("votes")
}

model Comment {
  id         String    @id @default(cuid())
  content    String
  pollId     String    @map("poll_id")
  authorName String    @map("author_name")
  userId     String?   @map("user_id")
  createdAt  DateTime  @default(now()) @map("created_at")
  updatedAt  DateTime? @updatedAt @map("updated_at")

  poll Poll  @relation(fields: [pollId], references: [id], onDelete: Cascade)
  user User? @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([pollId])
  @@index([userId])
  @@map("comments")
}