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

Method parse

packages/migrate/src/commands/MigrateResolve.ts:63–175  ·  view source on GitHub ↗
(argv: string[], config: PrismaConfigInternal, baseDir: string)

Source from the content-addressed store, hash-verified

61`)
62
63 public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> {
64 const args = arg(
65 argv,
66 {
67 '--help': Boolean,
68 '-h': '--help',
69 '--applied': String,
70 '--rolled-back': String,
71 '--schema': String,
72 '--config': String,
73 '--telemetry-information': String,
74 },
75 false,
76 )
77
78 if (isError(args)) {
79 return this.help(args.message)
80 }
81
82 if (args['--help']) {
83 return this.help()
84 }
85
86 const schemaContext = await loadSchemaContext({
87 schemaPath: createSchemaPathInput({
88 schemaPathFromArgs: args['--schema'],
89 schemaPathFromConfig: config.schema,
90 baseDir,
91 }),
92 })
93 const { migrationsDirPath } = inferDirectoryConfig(schemaContext, config)
94
95 const cmd = 'migrate resolve'
96 const validatedConfig = validatePrismaConfigWithDatasource({ config, cmd })
97
98 checkUnsupportedDataProxy({ cmd, validatedConfig })
99
100 printDatasource({ datasourceInfo: parseDatasourceInfo(schemaContext.primaryDatasource, validatedConfig) })
101
102 // if both are not defined
103 if (!args['--applied'] && !args['--rolled-back']) {
104 throw new Error(
105 `--applied or --rolled-back must be part of the command like:
106${bold(green(getCommandWithExecutor('prisma migrate resolve --applied 20201231000000_example')))}
107${bold(green(getCommandWithExecutor('prisma migrate resolve --rolled-back 20201231000000_example')))}`,
108 )
109 }
110 // if both are defined
111 else if (args['--applied'] && args['--rolled-back']) {
112 throw new Error('Pass either --applied or --rolled-back, not both.')
113 }
114
115 if (args['--applied']) {
116 if (typeof args['--applied'] !== 'string' || args['--applied'].length === 0) {
117 throw new Error(
118 `--applied value must be a string like ${bold(
119 green(getCommandWithExecutor('prisma migrate resolve --applied 20201231000000_example')),
120 )}`,

Callers

nothing calls this directly

Calls 15

helpMethod · 0.95
argFunction · 0.90
isErrorFunction · 0.90
loadSchemaContextFunction · 0.90
createSchemaPathInputFunction · 0.90
inferDirectoryConfigFunction · 0.90
printDatasourceFunction · 0.90
parseDatasourceInfoFunction · 0.90
getCommandWithExecutorFunction · 0.90

Tested by

no test coverage detected