Skip to content

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

♻️ Remove legacy start column (#1113)

Luke Vella533e3475570b
diff --git a/apps/web/src/components/scheduled-event.tsx b/apps/web/src/components/scheduled-event.tsx
index 1ef8d7e3b..70ea42c18 100644
--- a/apps/web/src/components/scheduled-event.tsx
+++ b/apps/web/src/components/scheduled-event.tsx
@@ -30,7 +30,7 @@ function FinalTime({ start, duration }: { start: Date; duration: number }) {
return <Trans i18nKey="allDay" />;
}
return (
- <span>{`${adjustTimeZone(start, !poll.timeZone).format("LT")} - ${adjustTimeZone(dayjs(start).add(duration, "minutes"), !poll.timeZone).format("LT")}`}</span>
+ <span>{`${adjustTimeZone(start, !poll.timeZone).format("LT")} - ${adjustTimeZone(dayjs(start).add(duration, "minutes"), !poll.timeZone).format(poll.timeZone ? "LT z" : "LT")}`}</span>
);
}
diff --git a/apps/web/src/contexts/current-event.ts b/apps/web/src/contexts/current-event.ts
index 2cd05b164..720556443 100644
--- a/apps/web/src/contexts/current-event.ts
+++ b/apps/web/src/contexts/current-event.ts
@@ -26,11 +26,6 @@ export type OptionScore = {
no: string[];
};
-export const useCurrentPollOptions = () => {
- const pollId = useCurrentEventId();
- return trpc.polls.options.list.useQuery({ pollId });
-};
-
export const useCreatePollLink = () => {
const pollId = useCurrentEventId();
const basePath = `/poll/${pollId}`;
diff --git a/apps/web/src/utils/trpc/types.ts b/apps/web/src/utils/trpc/types.ts
index 563981c21..c8e8adf85 100644
--- a/apps/web/src/utils/trpc/types.ts
+++ b/apps/web/src/utils/trpc/types.ts
@@ -5,7 +5,7 @@ export type GetPollApiResponse = {
title: string;
location: string | null;
description: string | null;
- options: { id: string; start: Date; startTime: Date; duration: number }[];
+ options: { id: string; startTime: Date; duration: number }[];
user: User | null;
timeZone: string | null;
adminUrlId: string;
diff --git a/packages/backend/trpc/routers/polls.ts b/packages/backend/trpc/routers/polls.ts
index 16705c3fb..6c91efc0d 100644
--- a/packages/backend/trpc/routers/polls.ts
+++ b/packages/backend/trpc/routers/polls.ts
@@ -17,7 +17,6 @@ import {
router,
} from "../trpc";
import { comments } from "./polls/comments";
-import { options } from "./polls/options";
import { participants } from "./polls/participants";
dayjs.extend(toArray);
@@ -44,7 +43,6 @@ const getPollIdFromAdminUrlId = async (urlId: string) => {
export const polls = router({
participants,
comments,
- options,
// START LEGACY ROUTES
create: possiblyPublicProcedure
.input(
@@ -101,7 +99,6 @@ export const polls = router({
options: {
createMany: {
data: input.options.map((option) => ({
- start: dayjs(option.startDate).utc(true).toDate(),
startTime: input.timeZone
? dayjs(option.startDate).tz(input.timeZone, true).toDate()
: dayjs(option.startDate).utc(true).toDate(),
@@ -375,12 +372,11 @@ export const polls = router({
options: {
select: {
id: true,
- start: true,
startTime: true,
duration: true,
},
orderBy: {
- start: "asc",
+ startTime: "asc",
},
},
user: true,
@@ -514,13 +510,6 @@ export const polls = router({
duration: true,
},
},
- options: {
- select: {
- id: true,
- start: true,
- duration: true,
- },
- },
closed: true,
participants: {
select: {
@@ -597,13 +586,6 @@ export const polls = router({
duration: true,
},
},
- options: {
- select: {
- id: true,
- start: true,
- duration: true,
- },
- },
closed: true,
participants: {
select: {
@@ -631,58 +613,6 @@ export const polls = router({
return { total, rows };
}),
- list: possiblyPublicProcedure.query(async ({ ctx }) => {
- const polls = await prisma.poll.findMany({
- where: {
- userId: ctx.user.id,
- deleted: false,
- },
- select: {
- id: true,
- title: true,
- location: true,
- createdAt: true,
- timeZone: true,
- adminUrlId: true,
- participantUrlId: true,
- status: true,
- event: {
- select: {
- start: true,
- duration: true,
- },
- },
- options: {
- select: {
- id: true,
- start: true,
- duration: true,
- },
- },
- closed: true,
- participants: {
- select: {
- id: true,
- name: true,
- },
- orderBy: [
- {
- createdAt: "desc",
- },
- { name: "desc" },
- ],
- },
- },
- orderBy: [
- {
- createdAt: "desc",
- },
- { title: "asc" },
- ],
- });
-
- return polls;
- }),
book: proProcedure
.input(
z.object({
@@ -743,7 +673,7 @@ export const polls = router({
id: input.optionId,
},
select: {
- start: true,
+ startTime: true,
duration: true,
},
});
@@ -755,10 +685,12 @@ export const polls = router({
});
}
- let eventStart = dayjs(option.start).utc();
+ let eventStart = dayjs(option.startTime);
if (poll.timeZone) {
- eventStart = eventStart.tz(poll.timeZone, true);
+ eventStart = eventStart.tz(poll.timeZone);
+ } else {
+ eventStart = eventStart.utc();
}
await prisma.poll.update({
@@ -992,7 +924,6 @@ export const polls = router({
disableComments: true,
options: {
select: {
- start: true,
startTime: true,
duration: true,
},
diff --git a/packages/backend/trpc/routers/polls/options.ts b/packages/backend/trpc/routers/polls/options.ts
deleted file mode 100644
index 4e6a99f82..000000000
--- a/packages/backend/trpc/routers/polls/options.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { prisma } from "@rallly/database";
-import { z } from "zod";
-
-import { publicProcedure, router } from "../../trpc";
-
-export const options = router({
- list: publicProcedure
- .input(
- z.object({
- pollId: z.string(),
- }),
- )
- .query(async ({ input: { pollId } }) => {
- const options = await prisma.option.findMany({
- where: {
- pollId,
- },
- select: {
- id: true,
- start: true,
- duration: true,
- },
- orderBy: [
- {
- start: "asc",
- },
- ],
- });
-
- return options;
- }),
- delete: publicProcedure
- .input(
- z.object({
- optionId: z.string(),
- }),
- )
- .mutation(async ({ input: { optionId } }) => {
- await prisma.option.delete({
- where: {
- id: optionId,
- },
- });
- }),
-});
diff --git a/packages/database/prisma/migrations/20240317095541_remove_legacy_start_column/migration.sql b/packages/database/prisma/migrations/20240317095541_remove_legacy_start_column/migration.sql
new file mode 100644
index 000000000..8aa2aa09d
--- /dev/null
+++ b/packages/database/prisma/migrations/20240317095541_remove_legacy_start_column/migration.sql
@@ -0,0 +1,8 @@
+/*
+ Warnings:
+
+ - You are about to drop the column `start` on the `options` table. All the data in the column will be lost.
+
+*/
+-- AlterTable
+ALTER TABLE "options" DROP COLUMN "start";
diff --git a/packages/database/prisma/schema.prisma b/packages/database/prisma/schema.prisma
index 69d3b977b..e0592478d 100644
--- a/packages/database/prisma/schema.prisma
+++ b/packages/database/prisma/schema.prisma
@@ -195,7 +195,6 @@ model Participant {
model Option {
id String @id @default(cuid())
- start DateTime @db.Timestamp(0) // @deprecated - use startTime
startTime DateTime @db.Timestamp(0) @map("start_time")
duration Int @default(0) @map("duration_minutes")
pollId String @map("poll_id")