MCPcopy
hub / github.com/prisma/prisma / parse

Method parse

packages/migrate/src/commands/DbSeed.ts:31–91  ·  view source on GitHub ↗
(argv: string[], config: PrismaConfigInternal)

Source from the content-addressed store, hash-verified

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}
47Did 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
62To 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 {

Callers

nothing calls this directly

Calls 5

helpMethod · 0.95
argFunction · 0.90
isErrorFunction · 0.90
formatFunction · 0.90
executeSeedCommandFunction · 0.90

Tested by

no test coverage detected