Repository navigation
feat(schema-files-loader): Support subfolders - #24378
Merged
Merged
Conversation
Logic is the following: - When asked to load files from folder, it is simple - we just recursively walk the tree and load all `.prisma` files. - When asked to find all files belonging to the same schema, we walk up the directory tree and stop and the last directory that had any `.prisma` files - this directory will be the root of the schema. So: ``` first ├── a.prisma └── b.prisma second ├── a.prisma └── b.prisma ``` `first` and `second` describe different schema. ``` root.prisma first ├── a.prisma └── b.prisma second ├── a.prisma └── b.prisma ``` all files belong to the same schema.
Contributor
size-limit report 📦
|
Contributor
|
Note: Linting error can be ignore, I already fixed it on |
Jolg42
approved these changes
Jun 3, 2024
Contributor
Author
|
Ok, I am going to merge this now, but if we find anything wrong with this feature before release we should revert it rather than rush a fix - it's nothing that can't be postponed until next release. |
aqrln
pushed a commit
that referenced
this pull request
Jul 20, 2026
### Problem
`loadSchemaFiles` follows symlinks that resolve to a directory, but it
never records which directories it already walked into. Two directories
that link to each other are enough to make it recurse forever:
```
schema/
a.prisma
nested/
b.prisma
link -> ..
```
Running `prisma validate --schema schema` on that layout never returns.
Because the recursion is async, there is no stack overflow and no error,
the command just sits there while memory keeps growing (136 MB to 303 MB
over 20 seconds in my case). Directory symlinks used to be skipped
entirely before #24378 reworked the traversal into a generic recursive
function, and the cycle was never accounted for after that change.
### Fix
The traversal now carries a set of directories it has already entered
and stops when it sees one again.
The set is keyed by the canonical path rather than the path the
directory was reached through, otherwise the same directory can be
entered twice under two different spellings. That is easy to hit on
macOS, where `/tmp` is a symlink to `/private/tmp`: pointing the schema
root at `/tmp/...` made the loader return `a.prisma` twice, once for
each spelling, and validation then failed with
```
The model "A" cannot be defined because a model with that name already exists.
```
To get the canonical path, `getEntryType` now reports `realPath` for
directories too. The field is optional, so resolvers that have no notion
of symlinks (`InMemoryFilesResolver`) are unaffected and fall back to
the entry path. The paths in the returned files are untouched, they are
still reported the way the user spelled the schema root.
The same change also removes duplicates for a directory that is
reachable twice without any cycle, which is a fix on its own: duplicated
files are rejected later by validation.
### Test
The new test drives `loadSchemaFiles` with a resolver that describes two
directories linking to each other, and reaches the root through a second
path so both parts of the fix are covered. The resolver gives up after a
fixed number of lookups, so a regression fails the test right away
instead of taking the worker down with it.
### Note
`ignores symlinks to directories` does not test what its name says. Its
fixture links to a directory that only contains `.gitkeep`, so the
loader does walk into it and simply finds no `.prisma` files. I left it
alone since it is unrelated to the cycle, but it is worth renaming at
some point.
lh0x00
pushed a commit
to lh0x00/prisma
that referenced
this pull request
Aug 9, 2026
…9740) ### Problem `loadSchemaFiles` follows symlinks that resolve to a directory, but it never records which directories it already walked into. Two directories that link to each other are enough to make it recurse forever: ``` schema/ a.prisma nested/ b.prisma link -> .. ``` Running `prisma validate --schema schema` on that layout never returns. Because the recursion is async, there is no stack overflow and no error, the command just sits there while memory keeps growing (136 MB to 303 MB over 20 seconds in my case). Directory symlinks used to be skipped entirely before prisma#24378 reworked the traversal into a generic recursive function, and the cycle was never accounted for after that change. ### Fix The traversal now carries a set of directories it has already entered and stops when it sees one again. The set is keyed by the canonical path rather than the path the directory was reached through, otherwise the same directory can be entered twice under two different spellings. That is easy to hit on macOS, where `/tmp` is a symlink to `/private/tmp`: pointing the schema root at `/tmp/...` made the loader return `a.prisma` twice, once for each spelling, and validation then failed with ``` The model "A" cannot be defined because a model with that name already exists. ``` To get the canonical path, `getEntryType` now reports `realPath` for directories too. The field is optional, so resolvers that have no notion of symlinks (`InMemoryFilesResolver`) are unaffected and fall back to the entry path. The paths in the returned files are untouched, they are still reported the way the user spelled the schema root. The same change also removes duplicates for a directory that is reachable twice without any cycle, which is a fix on its own: duplicated files are rejected later by validation. ### Test The new test drives `loadSchemaFiles` with a resolver that describes two directories linking to each other, and reaches the root through a second path so both parts of the fix are covered. The resolver gives up after a fixed number of lookups, so a regression fails the test right away instead of taking the worker down with it. ### Note `ignores symlinks to directories` does not test what its name says. Its fixture links to a directory that only contains `.gitkeep`, so the loader does walk into it and simply finds no `.prisma` files. I left it alone since it is unrelated to the cycle, but it is worth renaming at some point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Logic is the following:
recursively walk the tree and load all
.prismafiles.the directory tree and stop and the last directory that had any
.prismafiles - this directory will be the root of the schema.So:
firstandseconddescribe different schema.all files belong to the same schema.