Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🌱 Seed invite tokens in the production format
Luke Vella45c5e12bee1f
diff --git a/packages/database/prisma/seed.ts b/packages/database/prisma/seed.tsindex 123e90a85..4d87c858a 100644--- a/packages/database/prisma/seed.ts+++ b/packages/database/prisma/seed.ts@@ -1,7 +1,6 @@-import { randomUUID } from "node:crypto";import { PrismaPg } from "@prisma/adapter-pg";import { PrismaClient } from "../generated/prisma/client";-import { buildPollHistory } from "./seed/activity";+import { buildPollHistory, generateAccessToken } from "./seed/activity";import {eventTypes,polls,@@ -111,11 +110,15 @@ async function main() {const pollId = nextId();const optionIds = poll.options.map(() => nextId());const participantIds = poll.participants.map(() => nextId());+ const participantTokens = poll.participants.map(() =>+ generateAccessToken(),+ );const history = buildPollHistory({index: pollIndex,poll,optionIds,participantIds,+ participantTokens,nextId,});@@ -165,7 +168,7 @@ async function main() {email: part.email,note: part.note,userId: part.userId,- token: randomUUID().replace(/-/g, ""),+ token: participantTokens[participantIndex],createdAt: history.participantCreatedAt[participantIndex],},});diff --git a/packages/database/prisma/seed/activity.ts b/packages/database/prisma/seed/activity.tsindex 7ee87477f..efe73ba78 100644--- a/packages/database/prisma/seed/activity.ts+++ b/packages/database/prisma/seed/activity.ts@@ -1,3 +1,4 @@+import { randomUUID } from "node:crypto";import type { Prisma } from "../../generated/prisma/client";import type { PollDef } from "./data";@@ -6,6 +7,11 @@ import type { PollDef } from "./data";// between. Everything is derived from the poll definition and a per-poll// random stream, so reseeding produces the same history relative to today.+// 32 alphanumeric characters, the floor on Participant.token and PollInvite.token.+export function generateAccessToken() {+ return randomUUID().replace(/-/g, "");+}+const MINUTE = 60_000;const HOUR = 60 * MINUTE;const DAY = 24 * HOUR;@@ -53,6 +59,7 @@ export function buildPollHistory({poll,optionIds,participantIds,+ participantTokens,nextId,now = new Date(),}: {@@ -60,6 +67,7 @@ export function buildPollHistory({poll: PollDef;optionIds: string[];participantIds: string[];+ participantTokens: string[];nextId: () => string;now?: Date;}) {@@ -114,7 +122,8 @@ export function buildPollHistory({invites.push({id: nextId(),email: participant.email,- token: `${nextId()}-token`,+ // A response made through an invite takes the invite's token.+ token: participantTokens[i] ?? generateAccessToken(),participantId: participantIds[i],openedAt: new Date((responseTimes[i] ?? invitedAt) - 4 * MINUTE),createdAt: new Date(invitedAt),@@ -138,7 +147,7 @@ export function buildPollHistory({invites.push({id: nextId(),email,- token: `${nextId()}-token`,+ token: generateAccessToken(),openedAt: opened? new Date(between(invitedAt + HOUR, end)): undefined,