File tree Expand file tree Collapse file tree 4 files changed +45
-20
lines changed Expand file tree Collapse file tree 4 files changed +45
-20
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-console */
2
+ import { PrismaClient } from "@prisma/client" ;
3
+
4
+ const prisma = new PrismaClient ( ) ;
5
+
6
+ /**
7
+ * We set the the initializedAt key here, because this script is run when the
8
+ * app is first deployed.
9
+ **/
10
+ async function setInitializedAt ( ) {
11
+ // Check if app is already initialized
12
+ const initializedAt = await prisma . appSettings . findUnique ( {
13
+ where : {
14
+ key : 'initializedAt'
15
+ }
16
+ } ) ;
17
+
18
+ if ( initializedAt ) {
19
+ console . log ( 'App already initialized. Skipping.' ) ;
20
+ return ;
21
+ }
22
+
23
+ const now = new Date ( ) . toISOString ( ) ;
24
+
25
+ console . log ( `Setting initializedAt to ${ now } .` ) ;
26
+
27
+ await prisma . appSettings . upsert ( {
28
+ where : {
29
+ key : 'initializedAt' ,
30
+ } ,
31
+ // No update emulates findOrCreate
32
+ update : { } ,
33
+ create : {
34
+ key : 'initializedAt' ,
35
+ value : now
36
+ }
37
+ } ) ;
38
+ }
39
+
40
+ // Self executing function
41
+ ( async ( ) => {
42
+ await setInitializedAt ( ) ;
43
+ } ) ( ) ;
Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
2
3
3
node setup-database.js
4
+ node initialize.js
4
5
node server.js
Original file line number Diff line number Diff line change 12
12
"ts-lint" : " SKIP_ENV_VALIDATION=true tsc --noEmit --incremental" ,
13
13
"ts-lint:watch" : " SKIP_ENV_VALIDATION=true tsc --noEmit --incremental --watch" ,
14
14
"start" : " next start" ,
15
- "vercel-build" : " node ./setup-database.js && next build" ,
15
+ "vercel-build" : " node ./setup-database.js && node ./initialize.js && next build" ,
16
16
"knip" : " knip" ,
17
17
"test" : " vitest" ,
18
18
"load-test" : " docker run -i grafana/k6 run - <load-test.js"
Original file line number Diff line number Diff line change @@ -76,26 +76,7 @@ async function handleMigrations() {
76
76
}
77
77
}
78
78
79
- /**
80
- * We set the the initializedAt key here, because this script is run when the
81
- * app is first deployed.
82
- **/
83
- async function seedInitialisedAt ( ) {
84
- await prisma . appSettings . upsert ( {
85
- where : {
86
- key : 'initializedAt' ,
87
- } ,
88
- // No update emulates findOrCreate
89
- update : { } ,
90
- create : {
91
- key : 'initializedAt' ,
92
- value : new Date ( ) . toISOString ( )
93
- }
94
- } ) ;
95
- }
96
79
97
- // Self executing function
98
80
( async ( ) => {
99
81
await handleMigrations ( ) ;
100
- await seedInitialisedAt ( ) ;
101
82
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments