The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fallback to DATABASE_URL if PLANETSCALE_DATABASE_URL not set
Steven Teyc6086de1d55a
diff --git a/apps/docs/local-development.mdx b/apps/docs/local-development.mdxindex 6956a419ce..e357b2a498 100644--- a/apps/docs/local-development.mdx+++ b/apps/docs/local-development.mdx@@ -257,7 +257,7 @@ Prerequisites:Here, we are using the open-source [PlanetScale simulator](https://github.com/mattrobenolt/ps-http-sim) so the application can continue to use the `@planetscale/database` SDK.<Tip>- While we're using two different values in local development, in production or staging environments, the `PLANETSCALE_DATABASE_URL` and `DATABASE_URL` environment variables will both have the same value – the actual PlanetScale database URL.+ While we're using two different values in local development, in production or staging environments, you'll only need the `DATABASE_URL` value.</Tip></Step>diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex c1326f41be..981764d3fb 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -31,9 +31,9 @@ QSTASH_NEXT_SIGNING_KEY=# MySQL Database via Planetscale# Get your MySQL Database URL here: https://planetscale.com/docs/tutorials/connect-nodejs-app+DATABASE_URL="mysql://root:@localhost:3306/planetscale"# Set local development documentation for connecting to a local database: https://dub.co/docs/local-development#step-4-set-up-planetscale-database-PLANET_SCALE_DATABASE_URL=-DATABASE_URL=+PLANETSCALE_DATABASE_URL="http://root:unused@localhost:3900"# Generate a random secret here: https://generate-secret.vercel.app/32NEXTAUTH_SECRET=diff --git a/apps/web/app/api/auth/account-exists/route.ts b/apps/web/app/api/auth/account-exists/route.tsindex 951b3f76e3..fb6d3a8234 100644--- a/apps/web/app/api/auth/account-exists/route.ts+++ b/apps/web/app/api/auth/account-exists/route.ts@@ -1,6 +1,6 @@import { getIdentityHash } from "@/lib/edge";import { isWhitelistedEmail } from "@/lib/edge-config";-import { conn } from "@/lib/planetscale";+import { DATABASE_URL, conn } from "@/lib/planetscale";import { ratelimit } from "@/lib/upstash";import { NextRequest, NextResponse } from "next/server";@@ -17,7 +17,7 @@ export async function POST(req: NextRequest) {const { email } = (await req.json()) as { email: string };- if (!process.env.PLANETSCALE_DATABASE_URL) {+ if (!DATABASE_URL) {return new Response("Database connection not established", {status: 500,});diff --git a/apps/web/lib/analytics.ts b/apps/web/lib/analytics.tsindex 386c2d6690..8132ed71dc 100644--- a/apps/web/lib/analytics.ts+++ b/apps/web/lib/analytics.ts@@ -1,4 +1,4 @@-import { conn } from "./planetscale";+import { DATABASE_URL, conn } from "./planetscale";import z from "./zod";import { getAnalyticsQuerySchema } from "./zod/schemas/analytics";@@ -106,7 +106,7 @@ export const getAnalytics = async ({// Note: we're using decodeURIComponent in this function because that's how we store it in MySQL and Tinybirdif (- !process.env.PLANETSCALE_DATABASE_URL ||+ !DATABASE_URL ||!process.env.TINYBIRD_API_KEY ||!VALID_TINYBIRD_ENDPOINTS.includes(endpoint)) {diff --git a/apps/web/lib/planetscale.ts b/apps/web/lib/planetscale.tsindex 0b1a606df8..69050f20f1 100644--- a/apps/web/lib/planetscale.ts+++ b/apps/web/lib/planetscale.ts@@ -2,14 +2,17 @@ import { nanoid } from "@dub/utils";import { connect } from "@planetscale/database";import { DomainProps, ProjectProps } from "./types";+export const DATABASE_URL =+ process.env.PLANETSCALE_DATABASE_URL || process.env.DATABASE_URL;+export const pscale_config = {- url: process.env.PLANETSCALE_DATABASE_URL,+ url: DATABASE_URL,};export const conn = connect(pscale_config);export const getProjectViaEdge = async (projectId: string) => {- if (!process.env.PLANETSCALE_DATABASE_URL) return null;+ if (!DATABASE_URL) return null;const { rows } =(await conn.execute("SELECT * FROM Project WHERE id = ?", [projectId])) ||@@ -21,7 +24,7 @@ export const getProjectViaEdge = async (projectId: string) => {};export const getDomainViaEdge = async (domain: string) => {- if (!process.env.PLANETSCALE_DATABASE_URL) return null;+ if (!DATABASE_URL) return null;const { rows } =(await conn.execute("SELECT * FROM Domain WHERE slug = ?", [domain])) || {};@@ -32,7 +35,7 @@ export const getDomainViaEdge = async (domain: string) => {};export const checkIfKeyExists = async (domain: string, key: string) => {- if (!process.env.PLANETSCALE_DATABASE_URL) return null;+ if (!DATABASE_URL) return null;const { rows } =(await conn.execute(@@ -44,7 +47,7 @@ export const checkIfKeyExists = async (domain: string, key: string) => {};export const getLinkViaEdge = async (domain: string, key: string) => {- if (!process.env.PLANETSCALE_DATABASE_URL) return null;+ if (!DATABASE_URL) return null;const { rows } =(await conn.execute(