* Find the user's Prisma schema. * * Checks `PRISMA_SCHEMA_PATH` env var first, then falls back to common * locations: `schema.prisma` and `prisma/schema.prisma` in the project root.
(workPath: string)
| 58 | * locations: `schema.prisma` and `prisma/schema.prisma` in the project root. |
| 59 | */ |
| 60 | async function findUserSchema(workPath: string): Promise<string | null> { |
| 61 | const envPath = process.env.PRISMA_SCHEMA_PATH; |
| 62 | if (envPath) { |
| 63 | const resolved = isAbsolute(envPath) ? envPath : join(workPath, envPath); |
| 64 | try { |
| 65 | await fs.promises.access(resolved); |
| 66 | return resolved; |
| 67 | } catch { |
| 68 | debug(`PRISMA_SCHEMA_PATH=${envPath} not found at ${resolved}`); |
| 69 | return null; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | const candidates = [ |
| 74 | join(workPath, 'schema.prisma'), |
| 75 | join(workPath, 'prisma', 'schema.prisma'), |
| 76 | ]; |
| 77 | for (const candidate of candidates) { |
| 78 | try { |
| 79 | await fs.promises.access(candidate); |
| 80 | return candidate; |
| 81 | } catch { |
| 82 | // try next |
| 83 | } |
| 84 | } |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | /** Recursively collect file paths under `dir`, relative to `base`. */ |
| 89 | async function collectFiles(dir: string, base: string): Promise<string[]> { |