|
| 1 | +import { Script } from "../scriptRunner"; |
| 2 | +import { PrismaClient } from "../../dist"; |
| 3 | +import { confirmAction } from "../utils"; |
| 4 | + |
| 5 | +const chatNames = [ |
| 6 | + "How does the auth middleware work?", |
| 7 | + "Explain the search indexing pipeline", |
| 8 | + "Where are API routes defined?", |
| 9 | + "How to add a new database migration", |
| 10 | + "What is the repo sync process?", |
| 11 | + "Understanding the chat architecture", |
| 12 | + "How does SSO integration work?", |
| 13 | + "Explain the permission model", |
| 14 | + "Where is the webhook handler?", |
| 15 | + "How to configure environment variables", |
| 16 | + "Understanding the billing system", |
| 17 | + "How does the worker process jobs?", |
| 18 | + "Explain the caching strategy", |
| 19 | + "Where are the shared types defined?", |
| 20 | + "How does code search ranking work?", |
| 21 | + "Understanding the notification system", |
| 22 | + "How to add a new API endpoint", |
| 23 | + "Explain the deployment pipeline", |
| 24 | + "Where is error handling centralized?", |
| 25 | + "How does real-time updates work?", |
| 26 | + "Understanding the plugin system", |
| 27 | + "How to write integration tests", |
| 28 | + "Explain the file indexing process", |
| 29 | + "Where are the email templates?", |
| 30 | + "How does rate limiting work?", |
| 31 | + "Understanding the monorepo structure", |
| 32 | + "How to add a new feature flag", |
| 33 | + "Explain the logging setup", |
| 34 | + "Where is the GraphQL schema?", |
| 35 | + "How does the sidebar component work?", |
| 36 | +]; |
| 37 | + |
| 38 | +export const injectChatData: Script = { |
| 39 | + run: async (prisma: PrismaClient) => { |
| 40 | + const orgId = 1; |
| 41 | + |
| 42 | + const org = await prisma.org.findUnique({ |
| 43 | + where: { id: orgId } |
| 44 | + }); |
| 45 | + |
| 46 | + if (!org) { |
| 47 | + console.error(`Organization with id ${orgId} not found.`); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + const userIdArg = process.argv.find(arg => arg.startsWith("--user-id="))?.split("=")[1]; |
| 52 | + |
| 53 | + const user = userIdArg |
| 54 | + ? await prisma.user.findUnique({ where: { id: userIdArg } }) |
| 55 | + : await prisma.user.findFirst({ |
| 56 | + where: { |
| 57 | + orgs: { |
| 58 | + some: { orgId } |
| 59 | + } |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + if (!user) { |
| 64 | + console.error(userIdArg |
| 65 | + ? `User with id "${userIdArg}" not found.` |
| 66 | + : `No user found in org ${orgId}.` |
| 67 | + ); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + await confirmAction(`This will create ${chatNames.length} chats for user "${user.name ?? user.email}" in org ${orgId}.`); |
| 72 | + |
| 73 | + for (const name of chatNames) { |
| 74 | + await prisma.chat.create({ |
| 75 | + data: { |
| 76 | + name, |
| 77 | + orgId, |
| 78 | + createdById: user.id, |
| 79 | + messages: [], |
| 80 | + } |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + console.log(`Created ${chatNames.length} chats.`); |
| 85 | + } |
| 86 | +}; |
0 commit comments