Repository navigation
feat(schema folder): ORM 665 rework schema finding logic - #26663
Conversation
size-limit report 📦
|
8dc0e85 to
1eca050
Compare
dc8ce58 to
6ea340b
Compare
1eca050 to
4138276
Compare
4138276 to
cdcc7d3
Compare
3875ce0 to
17d3877
Compare
…and typed sql based on schema folder
17d3877 to
ab203e2
Compare
This PR cleans up some remains of unused methods and refactors some more cases to use the SchemaContext instead of `getSchema` variants. Note: Based on top of #26663 and requires it to be merged first.
|
Thanks for this improvement. I just observed one issue with different use case. When I am using multiple databases without But when I enable prismaSchemaFolder feature so that I can create multiple schema for a single db, all migrations are generated in Here: |
|
@AmreeshTyagi I assume you did your testing on Prisma version 6.5.0 or earlier, right? And do I get your use-case correct when I say:
And the issue being that once you want to have more than 1 If that's all true than the change from this PR should fix this for you with the upcoming 6.6.0 release as we now place the migrations folder next to the (Feel free to try a dev build already - e .g 6.6.0-dev.95) |
Yes. I have the same use case and I am using v.6.5.0. Good to know that it is fixed and planned in next release soon. I have tried this dev build and it worked well. Thanks a lot. |

ORM-665 Rework schema folder finding logic
Summary
./prisma/schemaas a folder is not checked by default anymore.schemaPathproperty inprisma.config.tsto point to a folder or file.Remove default folder resolving
Instead of trying to find a Prisma Schema folder implicitly based on default locations we want to simplify the resolve logic to:
--schemaCLI option with either folder or filenameprisma.config.ts- either folder or filename explicitly givenprisma.schema- path to folder or filename given./prisma/schema.prismaor./schema.prisma- no folder support(So far we would also check
./prisma/schemaif the preview feature is on.)Why this change? => So it is very explicit for the user that they switched from a default location of a single file to a folder / custom based setup which will change where we look for things.
Change default placement of migrations, views and typed sql folders
Also so far the schema folder has been the reference location to which we place the migrations, views and typed sql folders NEXT to it. Not into it. E.g.:
This was likely done this way to preserve the location of the migrations folder when switching from default single file (
./prisma/schema.prisma) to default folder location (./prisma/schema).Ideally we would also support glob patterns to find schema files across a larger variety of paths and enable more flexibility for the user.Even with the current refactoring, that is not easily possible, as we still have some legacy places that rely on the schema path structure (e.g. generators and env var loading).
To eventually support glob pattern based loading we cannot build our logic around a single file or directory path being passed in.
=> Determine the default location of those directories based on the location of the schema file that contains the datasource block. We already do this to find SQLite database files.
Note
Note: With ORM-663 and ORM-664 we will get additional customizable options.
Why this change? => Consistent behavior of how paths work in relation to schema files. Also most people should have their main schema.prisma file on the root of their specified schema path folder.
Unify config options
Most schema config options can take either a directory or a file. E.g. via the cli args or the
package.jsonfield. But for theprisma.config.tswe went with an explicit distinction. With the new code structure we don't really need this. We can easily detect whether a given path is a file or a folder and adjust our logic based on that.Also moving forward we should treat everything as "multi schema file". Having a single schema file is just a special case of that whose details are only relevant during the initial file loading.
So prisma.config.ts becomes:
Why this change? => It's easier to configure, reduces config and code complexity on our end, is aligned with how most other tools accept paths and opens an easy way forward should we later on want to support glob patterns.