File tree 6 files changed +75
-27
lines changed
app/future/apps/categories/[category]
6 files changed +75
-27
lines changed Original file line number Diff line number Diff line change 1
1
import CategoryPage , { type PageProps } from "@pages/apps/categories/[category]" ;
2
- import { Prisma } from "@prisma/client" ;
3
2
import { withAppDirSsg } from "app/WithAppDirSsg" ;
4
3
import { _generateMetadata } from "app/_utils" ;
5
4
import { WithLayout } from "app/layoutHOC" ;
6
5
7
6
import { APP_NAME } from "@calcom/lib/constants" ;
8
- import prisma from "@calcom/prisma" ;
9
7
import { AppCategories } from "@calcom/prisma/enums" ;
8
+ import { isPrismaAvailableCheck } from "@calcom/prisma/is-prisma-available-check" ;
10
9
11
10
import { getStaticProps } from "@lib/apps/categories/[category]/getStaticProps" ;
12
11
@@ -19,16 +18,11 @@ export const generateMetadata = async () => {
19
18
20
19
export const generateStaticParams = async ( ) => {
21
20
const paths = Object . keys ( AppCategories ) ;
21
+ const isPrismaAvailable = await isPrismaAvailableCheck ( ) ;
22
22
23
- try {
24
- await prisma . $queryRaw `SELECT 1` ;
25
- } catch ( e : unknown ) {
26
- if ( e instanceof Prisma . PrismaClientInitializationError ) {
27
- // Database is not available at build time. Make sure we fall back to building these pages on demand
28
- return [ ] ;
29
- } else {
30
- throw e ;
31
- }
23
+ if ( ! isPrismaAvailable ) {
24
+ // Database is not available at build time. Make sure we fall back to building these pages on demand
25
+ return [ ] ;
32
26
}
33
27
34
28
return paths . map ( ( category ) => ( { category } ) ) ;
Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
3
- import { Prisma } from "@prisma/client" ;
4
3
import type { InferGetStaticPropsType } from "next" ;
5
4
import Link from "next/link" ;
6
5
7
6
import Shell from "@calcom/features/shell/Shell" ;
8
7
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams" ;
9
8
import { useLocale } from "@calcom/lib/hooks/useLocale" ;
10
- import prisma from "@calcom/prisma" ;
11
9
import { AppCategories } from "@calcom/prisma/enums" ;
10
+ import { isPrismaAvailableCheck } from "@calcom/prisma/is-prisma-available-check" ;
12
11
import { AppCard , SkeletonText } from "@calcom/ui" ;
13
12
14
13
import { getStaticProps } from "@lib/apps/categories/[category]/getStaticProps" ;
@@ -62,19 +61,13 @@ Apps.PageWrapper = PageWrapper;
62
61
63
62
export const getStaticPaths = async ( ) => {
64
63
const paths = Object . keys ( AppCategories ) ;
65
-
66
- try {
67
- await prisma . $queryRaw `SELECT 1` ;
68
- } catch ( e : unknown ) {
69
- if ( e instanceof Prisma . PrismaClientInitializationError ) {
70
- // Database is not available at build time. Make sure we fall back to building these pages on demand
71
- return {
72
- paths : [ ] ,
73
- fallback : "blocking" ,
74
- } ;
75
- } else {
76
- throw e ;
77
- }
64
+ const isPrismaAvailable = await isPrismaAvailableCheck ( ) ;
65
+ if ( ! isPrismaAvailable ) {
66
+ // Database is not available at build time. Make sure we fall back to building these pages on demand
67
+ return {
68
+ paths : [ ] ,
69
+ fallback : "blocking" ,
70
+ } ;
78
71
}
79
72
80
73
return {
Original file line number Diff line number Diff line change
1
+ import dotEnv from "dotenv" ;
2
+ import { exec as execCb } from "node:child_process" ;
3
+ import { promisify } from "node:util" ;
4
+
5
+ import { isPrismaAvailableCheck } from "./is-prisma-available-check" ;
6
+
7
+ dotEnv . config ( { path : "../../.env" } ) ;
8
+
9
+ const exec = promisify ( execCb ) ;
10
+
11
+ /**
12
+ * TODO: re-write this when Prisma.io gets a programmatic migration API
13
+ * Thanks to @olalonde for the idea.
14
+ * @see https://github.com/prisma/prisma/issues/4703#issuecomment-1447354363
15
+ */
16
+ async function main ( ) : Promise < void > {
17
+ if ( ! process . env . DATABASE_URL ) {
18
+ console . info ( "No DATABASE_URL found, skipping migrations" ) ;
19
+ return ;
20
+ }
21
+ if ( ! process . env . DATABASE_DIRECT_URL ) {
22
+ console . info ( "No DATABASE_DIRECT_URL found, skipping migrations" ) ;
23
+ return ;
24
+ }
25
+ if ( ! ( await isPrismaAvailableCheck ( ) ) ) {
26
+ console . info ( "Prisma can't be initialized, skipping migrations" ) ;
27
+ return ;
28
+ }
29
+ // throws an error if migration fails
30
+ const { stdout, stderr } = await exec ( "yarn prisma migrate deploy" , {
31
+ env : {
32
+ ...process . env ,
33
+ } ,
34
+ } ) ;
35
+ console . log ( stdout ) ;
36
+ console . error ( stderr ) ;
37
+ }
38
+
39
+ main ( ) . catch ( ( e ) => {
40
+ console . error ( e . stdout || e . stderr || e . message ) ;
41
+ process . exit ( 1 ) ;
42
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { Prisma } from "@prisma/client" ;
2
+
3
+ import prisma from "." ;
4
+
5
+ export async function isPrismaAvailableCheck ( ) {
6
+ try {
7
+ await prisma . $queryRaw `SELECT 1` ;
8
+ return true ;
9
+ } catch ( e : unknown ) {
10
+ if ( e instanceof Prisma . PrismaClientInitializationError ) {
11
+ // Database might not available at build time.
12
+ return false ;
13
+ } else {
14
+ throw e ;
15
+ }
16
+ }
17
+ }
Original file line number Diff line number Diff line change 4
4
"private" : true ,
5
5
"scripts" : {
6
6
"clean" : " rm -rf .turbo && rm -rf node_modules" ,
7
- "build" : " yarn prisma migrate deploy || true " ,
7
+ "build" : " ts-node --transpile-only ./auto-migrations.ts " ,
8
8
"db-deploy" : " yarn prisma migrate deploy" ,
9
9
"db-migrate" : " yarn prisma migrate dev" ,
10
10
"db-nuke" : " docker compose down --volumes --remove-orphans || docker-compose down --volumes --remove-orphans" ,
Original file line number Diff line number Diff line change 237
237
" DAILY_API_KEY" ,
238
238
" DAILY_SCALE_PLAN" ,
239
239
" DAILY_WEBHOOK_SECRET" ,
240
+ " DATABASE_DIRECT_URL" ,
241
+ " DATABASE_URL" ,
240
242
" DEBUG" ,
241
243
" E2E_TEST_APPLE_CALENDAR_EMAIL" ,
242
244
" E2E_TEST_APPLE_CALENDAR_PASSWORD" ,
You can’t perform that action at this time.
0 commit comments