-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
initialize.js
43 lines (36 loc) · 897 Bytes
/
initialize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint-disable no-console */
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
/**
* We set the the initializedAt key here, because this script is run when the
* app is first deployed.
**/
async function setInitializedAt() {
// Check if app is already initialized
const initializedAt = await prisma.appSettings.findUnique({
where: {
key: 'initializedAt'
}
});
if (initializedAt) {
console.log('App already initialized. Skipping.');
return;
}
const now = new Date().toISOString();
console.log(`Setting initializedAt to ${now}.`);
await prisma.appSettings.upsert({
where: {
key: 'initializedAt',
},
// No update emulates findOrCreate
update: {},
create: {
key: 'initializedAt',
value: now
}
});
}
// Self executing function
(async () => {
await setInitializedAt();
})();