-
Notifications
You must be signed in to change notification settings - Fork 10
/
seed-data.ts
36 lines (31 loc) · 941 Bytes
/
seed-data.ts
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
import { isCuid } from 'cuid'
import { keystoneContext } from 'keystone/context'
import { seedDatabase } from 'lib/seed'
async function main() {
const context = keystoneContext
console.log(`🌱 Inserting seed data`)
if (
process.env.MAKE_ADMIN_ADDRESS &&
isCuid(process.env.MAKE_ADMIN_ADDRESS)
) {
const adminCount = await context.sudo().query.User.count({
where: { role: { equals: 'ADMIN' } },
})
if (adminCount === 0) {
const userId = process.env.MAKE_ADMIN_ADDRESS
if (context.session && userId === context.session.userId) {
await context.sudo().query.User.updateOne({
where: { id: userId },
data: { role: 'ADMIN' },
})
console.log(`Made ${userId} an admin`)
}
}
}
await seedDatabase()
console.log(`✅ Seed data inserted`)
console.log(
`👋 Please start the process with \`yarn dev\` or \`npm run dev\``,
)
}
main()