diff --git a/apps/web/package.json b/apps/web/package.json index 1deb3bd0..35ffc380 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -28,7 +28,9 @@ "@monaco-editor/react": "^4.5.1", "@next-auth/prisma-adapter": "1.0.5", "@next/mdx": "13.3.4", - "@prisma/client": "5.2.0-integration-fix-enums-browser.1", + "@planetscale/database": "^1.11.0", + "@prisma/adapter-planetscale": "5.4.2", + "@prisma/client": "5.4.2", "@radix-ui/react-avatar": "^1.0.2", "@radix-ui/react-dropdown-menu": "^2.0.4", "@radix-ui/react-navigation-menu": "^1.1.3", @@ -123,7 +125,7 @@ "postcss": "^8.4.21", "prettier": "^2.8.7", "prettier-plugin-tailwindcss": "^0.1.13", - "prisma": "5.2.0-integration-fix-enums-browser.1", + "prisma": "5.4.2", "tailwindcss": "^3.3.1", "ts-node": "^10.9.1", "tsconfig-paths": "^4.2.0", @@ -132,4 +134,4 @@ "ct3aMetadata": { "initVersion": "6.11.1" } -} \ No newline at end of file +} diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma index f551c263..46dd4d7d 100644 --- a/apps/web/prisma/schema.prisma +++ b/apps/web/prisma/schema.prisma @@ -2,7 +2,8 @@ // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] } datasource db { diff --git a/apps/web/src/env/schema.mjs b/apps/web/src/env/schema.mjs index 0f0c71bc..e4c08dfc 100644 --- a/apps/web/src/env/schema.mjs +++ b/apps/web/src/env/schema.mjs @@ -31,6 +31,7 @@ export const serverSchema = z.object({ GOOGLE_CLIENT_ID: z.string().optional(), GOOGLE_CLIENT_SECRET: z.string().optional(), HASHING_SECRET: z.string().min(1), + USE_PLANETSCALE: z.boolean().default(true), }); /** diff --git a/apps/web/src/server/db/client.ts b/apps/web/src/server/db/client.ts index 0e7cf750..b5879e15 100644 --- a/apps/web/src/server/db/client.ts +++ b/apps/web/src/server/db/client.ts @@ -1,4 +1,6 @@ import { PrismaClient } from "@prisma/client"; +import { connect } from "@planetscale/database"; +import { PrismaPlanetScale } from "@prisma/adapter-planetscale"; import { env } from "../../env/server.mjs"; @@ -9,9 +11,16 @@ declare global { export const prisma = global.prisma || - new PrismaClient({ - log: ["error"], - }); + // enable planetscale adapter in production if enabled + (env.NODE_ENV === "production" && env.USE_PLANETSCALE + ? (() => { + const connection = connect({ url: env.DATABASE_URL }); + const adapter = new PrismaPlanetScale(connection); + return new PrismaClient({ adapter, log: ["error"] }); + })() + : new PrismaClient({ + log: ["error"], + })); if (env.NODE_ENV !== "production") { global.prisma = prisma; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebce5e37..ea763c78 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -198,13 +198,19 @@ importers: version: 4.5.1(monaco-editor@0.39.0)(react-dom@18.2.0)(react@18.2.0) '@next-auth/prisma-adapter': specifier: 1.0.5 - version: 1.0.5(@prisma/client@5.2.0-integration-fix-enums-browser.1)(next-auth@4.22.1) + version: 1.0.5(@prisma/client@5.4.2)(next-auth@4.22.1) '@next/mdx': specifier: 13.3.4 version: 13.3.4(@mdx-js/loader@2.3.0)(@mdx-js/react@2.3.0) + '@planetscale/database': + specifier: ^1.11.0 + version: 1.11.0 + '@prisma/adapter-planetscale': + specifier: 5.4.2 + version: 5.4.2(@planetscale/database@1.11.0) '@prisma/client': - specifier: 5.2.0-integration-fix-enums-browser.1 - version: 5.2.0-integration-fix-enums-browser.1(prisma@5.2.0-integration-fix-enums-browser.1) + specifier: 5.4.2 + version: 5.4.2(prisma@5.4.2) '@radix-ui/react-avatar': specifier: ^1.0.2 version: 1.0.3(@types/react-dom@18.0.5)(@types/react@18.0.14)(react-dom@18.2.0)(react@18.2.0) @@ -483,8 +489,8 @@ importers: specifier: ^0.1.13 version: 0.1.13(prettier@2.8.8) prisma: - specifier: 5.2.0-integration-fix-enums-browser.1 - version: 5.2.0-integration-fix-enums-browser.1 + specifier: 5.4.2 + version: 5.4.2 tailwindcss: specifier: ^3.3.1 version: 3.3.2(ts-node@10.9.1) @@ -6455,13 +6461,13 @@ packages: tar-fs: 2.1.1 dev: true - /@next-auth/prisma-adapter@1.0.5(@prisma/client@5.2.0-integration-fix-enums-browser.1)(next-auth@4.22.1): + /@next-auth/prisma-adapter@1.0.5(@prisma/client@5.4.2)(next-auth@4.22.1): resolution: {integrity: sha512-VqMS11IxPXrPGXw6Oul6jcyS/n8GLOWzRMrPr3EMdtD6eOalM6zz05j08PcNiis8QzkfuYnCv49OvufTuaEwYQ==} peerDependencies: '@prisma/client': '>=2.26.0 || >=3' next-auth: ^4 dependencies: - '@prisma/client': 5.2.0-integration-fix-enums-browser.1(prisma@5.2.0-integration-fix-enums-browser.1) + '@prisma/client': 5.4.2(prisma@5.4.2) next-auth: 4.22.1(next@13.4.8)(nodemailer@6.9.3)(react-dom@18.2.0)(react@18.2.0) dev: false @@ -7139,6 +7145,11 @@ packages: tslib: 2.5.3 dev: false + /@planetscale/database@1.11.0: + resolution: {integrity: sha512-aWbU+D/IRHoDE9975y+Q4c+EwwAWxCPwFId+N1AhQVFXzbeJMkj6KN2iQtoi03elcLMRdfT+V3i9Z4WRw+/oIA==} + engines: {node: '>=16'} + dev: false + /@polka/url@0.5.0: resolution: {integrity: sha512-oZLYFEAzUKyi3SKnXvj32ZCEGH6RDnao7COuCVhDydMS9NrCSVXhM79VaKyP5+Zc33m0QXEd2DN3UkU7OsHcfw==} dev: false @@ -7151,8 +7162,19 @@ packages: resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==} dev: false - /@prisma/client@5.2.0-integration-fix-enums-browser.1(prisma@5.2.0-integration-fix-enums-browser.1): - resolution: {integrity: sha512-B6VNuBYuZiB35hR6Ze6c5E6mzSYcFHjbl3LFwCVNXQLUXskWF9KNJQmlHmyLURtrQ9Kf3VUuI6LYKWFWpZWlXw==} + /@prisma/adapter-planetscale@5.4.2(@planetscale/database@1.11.0): + resolution: {integrity: sha512-jTmjk1rZSju+f/gEMEhD2Pq8LsRb0BPu9PxP45tvaBMASoQYiyWzJsaV+eVeY8iJ9Yu/h68RGONO1deCZ7O8Fw==} + peerDependencies: + '@planetscale/database': ^1.11.0 + dependencies: + '@planetscale/database': 1.11.0 + '@prisma/driver-adapter-utils': 5.4.2 + transitivePeerDependencies: + - supports-color + dev: false + + /@prisma/client@5.4.2(prisma@5.4.2): + resolution: {integrity: sha512-2xsPaz4EaMKj1WS9iW6MlPhmbqtBsXAOeVttSePp8vTFTtvzh2hZbDgswwBdSCgPzmmwF+tLB259QzggvCmJqA==} engines: {node: '>=16.13'} requiresBuild: true peerDependencies: @@ -7161,16 +7183,24 @@ packages: prisma: optional: true dependencies: - '@prisma/engines-version': 5.1.0-28.a9b7003df90aa623086e4d6f4e43c72468e6339b - prisma: 5.2.0-integration-fix-enums-browser.1 + '@prisma/engines-version': 5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574 + prisma: 5.4.2 + dev: false + + /@prisma/driver-adapter-utils@5.4.2: + resolution: {integrity: sha512-V+mtlBXBxQuiOufaSH98S3x2j9G1G0+tgnx3lAlfd6YEeceTCcFFhg85rESW9UIshHvULeGFJsG7+qScgGX0Ng==} + dependencies: + debug: 4.3.4 + transitivePeerDependencies: + - supports-color dev: false - /@prisma/engines-version@5.1.0-28.a9b7003df90aa623086e4d6f4e43c72468e6339b: - resolution: {integrity: sha512-jTwE2oy1yjICmTfnCR0ASIpuMZXZ18sUzQXB7V0RMbrM9OlcmbUwXPuYhnxXuWN8XwRmujeIhsXs/Zeh+fjPOQ==} + /@prisma/engines-version@5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574: + resolution: {integrity: sha512-wvupDL4AA1vf4TQNANg7kR7y98ITqPsk6aacfBxZKtrJKRIsWjURHkZCGcQliHdqCiW/hGreO6d6ZuSv9MhdAA==} dev: false - /@prisma/engines@5.2.0-integration-fix-enums-browser.1: - resolution: {integrity: sha512-l3nuQH606fJZ+AwucfMOzC6wq0zepCkTcZ+N2a0lQVHHk+RTvIIBmZDO9wg78bYQuclYBQwcLPpjwVqS+8dNLg==} + /@prisma/engines@5.4.2: + resolution: {integrity: sha512-fqeucJ3LH0e1eyFdT0zRx+oETLancu5+n4lhiYECyEz6H2RDskPJHJYHkVc0LhkU4Uv7fuEnppKU3nVKNzMh8g==} requiresBuild: true /@radix-ui/number@1.0.1: @@ -19550,13 +19580,13 @@ packages: js-beautify: 1.14.8 dev: false - /prisma@5.2.0-integration-fix-enums-browser.1: - resolution: {integrity: sha512-Ex6xB3MtqZKRzXUDqWSe1AuVy+++NAkmjEiF81KuFWNkoDV0W0mY+cBvw2CpXw3GNLB0SqE/tkEHO4aRoNryOg==} + /prisma@5.4.2: + resolution: {integrity: sha512-GDMZwZy7mysB2oXU+angQqJ90iaPFdD0rHaZNkn+dio5NRkGLmMqmXs31//tg/qXT3iB0cTQwnGGQNuirhSTZg==} engines: {node: '>=16.13'} hasBin: true requiresBuild: true dependencies: - '@prisma/engines': 5.2.0-integration-fix-enums-browser.1 + '@prisma/engines': 5.4.2 /proc-log@3.0.0: resolution: {integrity: sha512-++Vn7NS4Xf9NacaU9Xq3URUuqZETPsf8L4j5/ckhaRYsfPeRyzGw+iDjFhV/Jr3uNmTvvddEJFWh5R1gRgUH8A==}