MCPcopy
hub / github.com/prisma/prisma / getSchemaWithPathInternal

Function getSchemaWithPathInternal

packages/internals/src/cli/getSchema.ts:170–201  ·  view source on GitHub ↗

* Tries to load schema from either provided * arg, prisma.config.ts location, default location relative to cwd * or any of the Yarn1Workspaces. * * If schema is specified explicitly with any of the methods but can * not be loaded, error will be thrown. If no explicit schema is given, then * er

({
  schemaPath,
  cwd,
  argumentName,
}: GetSchemaInternalOptions)

Source from the content-addressed store, hash-verified

168 * error value will be returned instead
169 */
170async function getSchemaWithPathInternal({
171 schemaPath,
172 cwd,
173 argumentName,
174}: GetSchemaInternalOptions): Promise<DefaultLookupResult> {
175 // 1. Try the user custom path, when provided.
176 if ('cliProvidedPath' in schemaPath) {
177 return {
178 ok: true,
179 schema: await getCliProvidedSchemaFile(schemaPath.cliProvidedPath, cwd, argumentName),
180 }
181 }
182
183 // 2. Try the `schema` from `PrismaConfig`
184 if ('configProvidedPath' in schemaPath) {
185 return {
186 ok: true,
187 schema: await getConfigProvidedSchemaFile(schemaPath.configProvidedPath),
188 }
189 }
190
191 // 3. Look into the default, "canonical" locations in the cwd (e.g., `./schema.prisma` or `./prisma/schema.prisma`)
192 const defaultResult = await getDefaultSchema(schemaPath.baseDir)
193 if (defaultResult.ok) {
194 return defaultResult
195 }
196
197 return {
198 ok: false as const,
199 error: defaultResult.error,
200 }
201}
202
203function renderLookupError(error: NonFatalLookupError) {
204 switch (error.kind) {

Callers 2

getSchemaWithPathFunction · 0.85

Calls 3

getCliProvidedSchemaFileFunction · 0.85
getDefaultSchemaFunction · 0.85

Tested by

no test coverage detected