Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

remove deprecated field, add internal field

Steven Teyab35aafabe48
diff --git a/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx b/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx
index 76e517d799..4fd11fa6bb 100644
--- a/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx
+++ b/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx
@@ -4,7 +4,7 @@ import EmptyState from "@/ui/shared/empty-state";
import { sendEmail } from "@dub/email";
import EmailUpdated from "@dub/email/templates/email-updated";
import { prisma } from "@dub/prisma";
-import { User, VerificationToken } from "@dub/prisma/client";
+import { VerificationToken } from "@dub/prisma/client";
import { InputPassword, LoadingSpinner } from "@dub/ui";
import { waitUntil } from "@vercel/functions";
import { redirect } from "next/navigation";
@@ -97,8 +97,6 @@ const VerifyEmailChange = async ({ params, searchParams }: PageProps) => {
);
}
- let user: Pick<User, "subscribed"> | null = null;
-
// Update the partner profile email
if (data.isPartnerProfile) {
if (!partnerId) {
@@ -123,7 +121,7 @@ const VerifyEmailChange = async ({ params, searchParams }: PageProps) => {
// Update the user email
else {
- user = await prisma.user.update({
+ await prisma.user.update({
where: {
id: userId,
},
diff --git a/apps/web/scripts/send-batch-emails.ts b/apps/web/scripts/send-batch-emails.ts
index 7c7516d00f..a7660a0e69 100644
--- a/apps/web/scripts/send-batch-emails.ts
+++ b/apps/web/scripts/send-batch-emails.ts
@@ -7,6 +7,7 @@ import { generateUnsubscribeToken } from "../lib/email/unsubscribe-token";
async function main() {
const usersToNotify = await prisma.user.findMany({
where: {
+ sentMail: false,
notificationPreferences: {
partnerAccount: true,
},
@@ -14,6 +15,7 @@ async function main() {
some: {},
},
},
+ take: 1000,
});
console.log(`Found ${usersToNotify.length} users to notify`);
@@ -31,6 +33,18 @@ async function main() {
);
console.log(res);
+
+ const updatedUsers = await prisma.user.updateMany({
+ where: {
+ id: {
+ in: usersToNotify.map((user) => user.id),
+ },
+ },
+ data: {
+ sentMail: true,
+ },
+ });
+ console.log(`Updated ${updatedUsers.count} users to sentMail: true`);
}
main();
diff --git a/packages/prisma/schema/schema.prisma b/packages/prisma/schema/schema.prisma
index dc02c18c40..621c667ea3 100644
--- a/packages/prisma/schema/schema.prisma
+++ b/packages/prisma/schema/schema.prisma
@@ -15,21 +15,25 @@ model User {
emailVerified DateTime?
image String?
isMachine Boolean @default(false)
+ createdAt DateTime @default(now())
- // password data
+ // password & security fields
passwordHash String?
invalidLoginAttempts Int @default(0)
lockedAt DateTime?
- createdAt DateTime @default(now())
- subscribed Boolean @default(true) // TODO: deprecrate once notificationPreferences is fully migrated
- notificationPreferences UserNotificationPreferences?
- source String? // where the user came from
- defaultWorkspace String? // slug of the user's default workspace
- defaultPartnerId String? // the user's default partner ID
+ // user preferences
+ defaultWorkspace String? // slug of the user's default workspace
+ defaultPartnerId String? // the user's default partner ID
+
+ // internal fields
+ source String? // where the user came from
+ sentMail Boolean @default(false)
+
// relational data
accounts Account[]
sessions Session[]
+ notificationPreferences UserNotificationPreferences?
projects ProjectUsers[]
partners PartnerUser[]
links Link[]
@@ -49,6 +53,7 @@ model User {
fraudEventGroups FraudEventGroup[]
activityLogs ActivityLog[]
+ @@index(sentMail)
@@index(source)
@@index(defaultWorkspace)
}