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.

migrate script, free projects limit

Steven Tey92e6c05c159f
diff --git a/apps/web/app/api/callback/stripe/route.ts b/apps/web/app/api/callback/stripe/route.ts
index 1357f06ffb..13151b9b74 100644
--- a/apps/web/app/api/callback/stripe/route.ts
+++ b/apps/web/app/api/callback/stripe/route.ts
@@ -2,7 +2,7 @@ import { limiter } from "@/lib/cron";
import prisma from "@/lib/prisma";
import { stripe } from "@/lib/stripe";
import { redis } from "@/lib/upstash";
-import { PLANS, getPlanFromPriceId, log } from "@dub/utils";
+import { FREE_PLAN, getPlanFromPriceId, log } from "@dub/utils";
import { resend, sendEmail } from "emails";
import UpgradeEmail from "emails/upgrade-email";
import { NextResponse } from "next/server";
@@ -231,8 +231,6 @@ export const POST = async (req: Request) => {
pipeline.del(`root:${domain}`);
});
- const FREE_PLAN = PLANS.find((plan) => plan.name === "free")!;
-
await Promise.allSettled([
prisma.project.update({
where: {
diff --git a/apps/web/app/api/projects/route.ts b/apps/web/app/api/projects/route.ts
index 505465fbb7..cc11256bc3 100644
--- a/apps/web/app/api/projects/route.ts
+++ b/apps/web/app/api/projects/route.ts
@@ -7,7 +7,11 @@ import {
import { withSession } from "@/lib/auth";
import { isReservedKey } from "@/lib/edge-config";
import prisma from "@/lib/prisma";
-import { DEFAULT_REDIRECTS, validSlugRegex } from "@dub/utils";
+import {
+ DEFAULT_REDIRECTS,
+ FREE_PROJECTS_LIMIT,
+ validSlugRegex,
+} from "@dub/utils";
// GET /api/projects - get all projects for the current user
export const GET = withSession(async ({ session }) => {
@@ -80,9 +84,9 @@ export const POST = withSession(async ({ req, session }) => {
},
});
- if (freeProjects >= 1) {
+ if (freeProjects >= FREE_PROJECTS_LIMIT) {
return new Response(
- "You can only create up to 2 free projects. Additional projects require a paid plan.",
+ `You can only create up to ${FREE_PROJECTS_LIMIT} free projects. Additional projects require a paid plan.`,
{ status: 403 },
);
}
diff --git a/apps/web/scripts/migrate.ts b/apps/web/scripts/migrate.ts
new file mode 100644
index 0000000000..5b084bbe49
--- /dev/null
+++ b/apps/web/scripts/migrate.ts
@@ -0,0 +1,56 @@
+import "dotenv-flow/config";
+import prisma from "@/lib/prisma";
+
+const DOMAIN = "x.com";
+const PROJECT_ID = "xxx";
+
+async function main() {
+ const [links, project] = await Promise.all([
+ prisma.link.updateMany({
+ where: {
+ domain: DOMAIN,
+ },
+ data: {
+ projectId: PROJECT_ID,
+ },
+ }),
+ prisma.project.findFirst({
+ where: {
+ domains: {
+ some: {
+ slug: DOMAIN,
+ },
+ },
+ },
+ }),
+ ]);
+
+ const response = await Promise.all([
+ prisma.domain.update({
+ where: {
+ slug: DOMAIN,
+ },
+ data: {
+ projectId: PROJECT_ID,
+ primary: false,
+ },
+ }),
+ prisma.project.update({
+ where: {
+ id: PROJECT_ID,
+ },
+ data: {
+ usage: {
+ increment: project?.usage,
+ },
+ linksUsage: {
+ increment: links.count,
+ },
+ },
+ }),
+ ]);
+
+ console.log({ response });
+}
+
+main();
diff --git a/apps/web/ui/projects/create-project-button.tsx b/apps/web/ui/projects/create-project-button.tsx
index db52c30cca..6d88e4d328 100644
--- a/apps/web/ui/projects/create-project-button.tsx
+++ b/apps/web/ui/projects/create-project-button.tsx
@@ -4,7 +4,7 @@ import useProjects from "@/lib/swr/use-projects";
import { ModalContext } from "@/ui/modals/provider";
import { Button } from "@dub/ui";
import { TooltipContent } from "@dub/ui/src/tooltip";
-import { HOME_DOMAIN } from "@dub/utils";
+import { FREE_PROJECTS_LIMIT, HOME_DOMAIN } from "@dub/utils";
import { useContext } from "react";
export default function CreateProjectButton() {
@@ -18,7 +18,7 @@ export default function CreateProjectButton() {
disabledTooltip={
exceedingFreeProjects ? (
<TooltipContent
- title="You can only create up to 2 free projects. Additional projects require a paid plan."
+ title={`You can only create up to ${FREE_PROJECTS_LIMIT} free projects. Additional projects require a paid plan.`}
cta="Upgrade to Pro"
href={
freeProjects
diff --git a/packages/utils/src/constants/pricing.tsx b/packages/utils/src/constants/pricing.tsx
index 4132a88518..e2855c25c7 100644
--- a/packages/utils/src/constants/pricing.tsx
+++ b/packages/utils/src/constants/pricing.tsx
@@ -194,6 +194,10 @@ export const PLANS = [
},
];
+export const FREE_PLAN = PLANS.find((plan) => plan.name === "free")!;
+
export const SELF_SERVE_PAID_PLANS = PLANS.filter(
(p) => p.name === "Pro" || p.name === "Business",
);
+
+export const FREE_PROJECTS_LIMIT = 2;