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.

Detect staging slug conflicts when Prisma cannot name the key

Rafieebe3b08ab71
diff --git a/apps/web/lib/sandbox/staging-slug.ts b/apps/web/lib/sandbox/staging-slug.ts
index 23abb12037..0bc4b6ca3a 100644
--- a/apps/web/lib/sandbox/staging-slug.ts
+++ b/apps/web/lib/sandbox/staging-slug.ts
@@ -18,8 +18,28 @@ export function isSlugUniqueConstraintError(error: unknown) {
const target = error.meta?.target;
const fields = Array.isArray(target) ? target : [target];
- return fields.some(
- (field) => typeof field === "string" && field.includes("slug"),
+ if (
+ fields.some((field) => typeof field === "string" && field.includes("slug"))
+ ) {
+ return true;
+ }
+
+ // The PlanetScale adapter often cannot parse the key name, so Prisma reports
+ // "(not available)" and `meta.target` is empty. The raw MySQL error still
+ // names the unique index, for example `Project.Project_slug_key`.
+ const cause = (
+ error.meta?.driverAdapterError as
+ | {
+ cause?: {
+ constraint?: { index?: string };
+ originalMessage?: string;
+ };
+ }
+ | undefined
+ )?.cause;
+
+ return [cause?.constraint?.index, cause?.originalMessage].some(
+ (value) => typeof value === "string" && value.includes("_slug_key"),
);
}