()
| 4 | import { prisma } from '@linen/database'; |
| 5 | |
| 6 | async function run() { |
| 7 | console.log('start', new Date()); |
| 8 | |
| 9 | const auths = await prisma.auths.findMany({ |
| 10 | include: { |
| 11 | users: true, |
| 12 | account: true, |
| 13 | }, |
| 14 | }); |
| 15 | for (const auth of auths) { |
| 16 | const { account, email } = auth; |
| 17 | if (!account) { |
| 18 | console.log(email, 'missing account, skip'); |
| 19 | continue; |
| 20 | } |
| 21 | const user = auth.users.find((user) => user.accountsId === account.id); |
| 22 | if (!!user) { |
| 23 | console.log(email, 'user already exists, skip'); |
| 24 | continue; |
| 25 | } |
| 26 | |
| 27 | const displayName = email.split('@').shift() || email; |
| 28 | |
| 29 | await prisma.users.create({ |
| 30 | data: { |
| 31 | isAdmin: true, |
| 32 | isBot: false, |
| 33 | account: { connect: { id: account.id } }, |
| 34 | auth: { connect: { id: auth.id } }, |
| 35 | anonymousAlias: generateRandomWordSlug(), |
| 36 | displayName, |
| 37 | }, |
| 38 | }); |
| 39 | console.log(email, 'user created'); |
| 40 | } |
| 41 | console.log('end', new Date()); |
| 42 | } |
| 43 | |
| 44 | run(); |
no test coverage detected