(argv: string[], config: PrismaConfigInternal)
| 29 | `) |
| 30 | |
| 31 | public async parse(argv: string[], config: PrismaConfigInternal): Promise<string | Error> { |
| 32 | const args = arg( |
| 33 | argv, |
| 34 | { |
| 35 | '--help': Boolean, |
| 36 | '-h': '--help', |
| 37 | '--schema': String, |
| 38 | '--config': String, |
| 39 | '--telemetry-information': String, |
| 40 | }, |
| 41 | false, |
| 42 | ) |
| 43 | |
| 44 | if (isError(args)) { |
| 45 | if (args instanceof ArgError && args.code === 'ARG_UNKNOWN_OPTION') { |
| 46 | throw new Error(`${args.message} |
| 47 | Did you mean to pass these as arguments to your seed script? If so, add a -- separator before them: |
| 48 | ${dim('$')} prisma db seed -- --arg1 value1 --arg2 value2`) |
| 49 | } |
| 50 | return this.help(args.message) |
| 51 | } |
| 52 | |
| 53 | if (args['--help']) { |
| 54 | return this.help() |
| 55 | } |
| 56 | |
| 57 | const seedCommand = config.migrations?.seed |
| 58 | |
| 59 | if (!seedCommand) { |
| 60 | return format(`⚠️ ${bold('No seed command configured')} |
| 61 | |
| 62 | To seed your database, add a ${bold('seed')} property to the ${bold('migrations')} section in your ${bold('Prisma config')} file. |
| 63 | |
| 64 | ${bold('Example')} |
| 65 | |
| 66 | ${dim('// prisma.config.ts')} |
| 67 | export default defineConfig({ |
| 68 | ${bold('migrations: {')} |
| 69 | ${bold(`seed: 'bun·./prisma/seed.ts'`)}, |
| 70 | ${bold('}')}, |
| 71 | ${dim('datasource: {')} |
| 72 | ${dim(`url: '[your database URL]'`)}, |
| 73 | ${dim('}')}, |
| 74 | }) |
| 75 | `) |
| 76 | } |
| 77 | |
| 78 | // We pass the extra params after a -- separator |
| 79 | // Example: db seed -- --custom-param |
| 80 | // Then args._ will be ['--custom-param'] |
| 81 | const extraArgs = args._.join(' ') |
| 82 | |
| 83 | // Seed command is set |
| 84 | // Execute user seed command |
| 85 | const successfulSeeding = await executeSeedCommand({ commandFromConfig: seedCommand, extraArgs }) |
| 86 | if (successfulSeeding) { |
| 87 | return `\n${process.platform === 'win32' ? '' : '🌱 '}The seed command has been executed.` |
| 88 | } else { |
nothing calls this directly
no test coverage detected