-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for splitting Prisma schema into multiple files #2377
Support for splitting Prisma schema into multiple files #2377
Comments
Like prisma one ... there was a feature like this implemented. |
Appreciate prioritisation of this. It is really painful to write all the schema in one file. |
badly need this feature. currently I have to |
Any update on this? |
Any movement on this? Really looking for this solution. |
It's a dealbreaker for me... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
until this is part of the prisma cli, we extracted a small script which we use internally into this tiny cli prisma-merge. its nothing fancy but works for us currently. feel free to use it or copy the source and tailor it to your needs. |
Ideally, I'd like my models to live near their/in modules in Nest. |
Would be a nice feature. A single file is not maintainable. |
Please, don't be hostile. I would love to see this feature as well coming to Prisma 2. There is a workaround (we used in some projects) which might help: cat *.part.prisma > schema.prisma
yarn prisma generate |
I think this is a "basic" feature for any project. Many months passed now, and there is no update on this. |
I agree that this is really needed, but Thank you guys and looking forward on this implementation :) |
Good workarounds exist and have been proposed, but one basic modular use case that is holding me back is this one: Module A:
Module B:
This wasn't possible in Prisma 1 either, but it would be amazing if the Prisma devs could make that happen. |
This would be very very awesome 👏 👏👏 |
* Implement multi-file schema handling in PSL This commit implements multi-file schema handling in the Prisma Schema Language. At a high level, instead of accepting a single string, `psl::validate_multi_file()` is an alternative to `psl::validate()` that accepts something morally equivalent to: ```json { "./prisma/schema/a.prisma": "datasource db { ... }", "./prisma/schema/nested/b.prisma": "model Test { ... }" } ``` There are tests for PSL validation with multiple schema files, but most of the rest of engines still consumes the single file version of `psl::validate()`. The implementation and the return type are shared between `psl::validate_multi_file()` and `psl::validate()`, so the change is completely transparent, other than the expectation of passing in a list of (file_name, file_contents) instead of a single string. The `psl::validate()` entry point should behave exactly the same as `psl::multi_schema()` with a single file named `schema.prisma`. In particular, it has the exact same return type. Implementation ============== This is achieved by extending `Span` to contain, in addition to a start and end offset, a `FileId`. The `FileId` is a unique identifier for a file and its parsed `SchemaAst` inside `ParserDatabase`. The identifier types for AST items in `ParserDatabase` are also extended to contain the `FileId`, so that they can be uniquely referred to in the context of the (multi-file) schema. After the analysis phase (the `parser_database` crate), consumers of the analyzed schema become multi-file aware completely transparently, no change is necessary in the other engines. The only changes that will be required at scattered points across the codebase are the `psl::validate()` call sites that will need to receive a `Vec<Box<Path>, SourceFile>` instead of a single `SourceFile`. This PR does _not_ deal with that, but it makes where these call sites are obvious by what entry points they use: `psl::validate()`, `psl::parse_schema()` and the various `*_assert_single()` methods on `ParserDatabase`. The PR contains tests confirming that schema analysis, validation and displaying diagnostics across multiple files works as expected. Status of this PR ================= This is going to be directly mergeable after review, and it will not affect the current schema handling behaviour when dealing with a single schema file. Next steps ========== - Replace all calls to `psl::validate()` with calls to `psl::validate_multi_file()`. - The `*_assert_single()` calls should be progressively replaced with their multi-file counterparts across engines. - The language server should start sending multiple files to prisma-schema-wasm in all calls. This is not in the spirit of the language server spec, but that is the most immediate solution. We'll have to make `range_to_span()` in `prisma-fmt` multi-schema aware by taking a FileId param. Links ===== Relevant issue: prisma/prisma#2377 Also see the [internal design doc](https://www.notion.so/prismaio/Multi-file-Schema-24d68fe8664048ad86252fe446caac24?d=68ef128f25974e619671a9855f65f44d#2889a038e68c4fe1ac9afe3cd34978bd). * chore(prisma-fmt): fix typo * chore(prisma-fmt): add comment * chore(prisma-fmt): fix compilation after #4137 --------- Co-authored-by: Alberto Schiabel <[email protected]> Co-authored-by: jkomyno <[email protected]>
* Implement multi-file schema handling in PSL This commit implements multi-file schema handling in the Prisma Schema Language. At a high level, instead of accepting a single string, `psl::validate_multi_file()` is an alternative to `psl::validate()` that accepts something morally equivalent to: ```json { "./prisma/schema/a.prisma": "datasource db { ... }", "./prisma/schema/nested/b.prisma": "model Test { ... }" } ``` There are tests for PSL validation with multiple schema files, but most of the rest of engines still consumes the single file version of `psl::validate()`. The implementation and the return type are shared between `psl::validate_multi_file()` and `psl::validate()`, so the change is completely transparent, other than the expectation of passing in a list of (file_name, file_contents) instead of a single string. The `psl::validate()` entry point should behave exactly the same as `psl::multi_schema()` with a single file named `schema.prisma`. In particular, it has the exact same return type. Implementation ============== This is achieved by extending `Span` to contain, in addition to a start and end offset, a `FileId`. The `FileId` is a unique identifier for a file and its parsed `SchemaAst` inside `ParserDatabase`. The identifier types for AST items in `ParserDatabase` are also extended to contain the `FileId`, so that they can be uniquely referred to in the context of the (multi-file) schema. After the analysis phase (the `parser_database` crate), consumers of the analyzed schema become multi-file aware completely transparently, no change is necessary in the other engines. The only changes that will be required at scattered points across the codebase are the `psl::validate()` call sites that will need to receive a `Vec<Box<Path>, SourceFile>` instead of a single `SourceFile`. This PR does _not_ deal with that, but it makes where these call sites are obvious by what entry points they use: `psl::validate()`, `psl::parse_schema()` and the various `*_assert_single()` methods on `ParserDatabase`. The PR contains tests confirming that schema analysis, validation and displaying diagnostics across multiple files works as expected. Status of this PR ================= This is going to be directly mergeable after review, and it will not affect the current schema handling behaviour when dealing with a single schema file. Next steps ========== - Replace all calls to `psl::validate()` with calls to `psl::validate_multi_file()`. - The `*_assert_single()` calls should be progressively replaced with their multi-file counterparts across engines. - The language server should start sending multiple files to prisma-schema-wasm in all calls. This is not in the spirit of the language server spec, but that is the most immediate solution. We'll have to make `range_to_span()` in `prisma-fmt` multi-schema aware by taking a FileId param. Links ===== Relevant issue: prisma/prisma#2377 Also see the [internal design doc](https://www.notion.so/prismaio/Multi-file-Schema-24d68fe8664048ad86252fe446caac24?d=68ef128f25974e619671a9855f65f44d#2889a038e68c4fe1ac9afe3cd34978bd). * WIP(schema-wasm): Support schema split into multiple files * Reformat support (psl crate) * Add multifile reformatting tests * Clippy * feat(prisma-fmt): addd support for mergeSchemas, expose functions to prisma-fmt-wasm * chore(prisma-fmt): removed unused function * chore: fix typo Co-authored-by: Serhii Tatarintsev <[email protected]> * feat(prisma-fmt): apply validation to merge_schemas * chore(prisma-fmt): update unit test * chore: fix bad merge * chore: fix tests --------- Co-authored-by: Tom Houlé <[email protected]> Co-authored-by: Alberto Schiabel <[email protected]> Co-authored-by: jkomyno <[email protected]>
Can this resolve the problem? |
It's solve, but this is the horrible thing about the JS ecosystem; everything it's a lot bundle of packages. In my opinion the Prisma developer should take your package and implement the code into the prisma. Or, you create a pull request that envolve the package. Personally I'll wouldn't install more JS packages to solve an issue of an JS package. If you think about it, is something quite bad for community. |
Well spotted @nlynzaad, we have indeed started work on this functionality. |
…prisma#2377 is resolved through prisma-multischema
…prisma#2377 is resolved through prisma-multischema
…prisma#2377 is resolved through prisma-multischema
…prisma#2377 is resolved through prisma-multischema
…prisma#2377 is resolved through prisma-multischema
…prisma#2377 is resolved through prisma-multischema
#2377 (comment) No need for this. I didn't see anything too unreasonable. Looking forward to this feature. It'd be nice if we could target a folder and all of the schema files within that folder get picked up. Similar to how HCL with Terraform works.
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This commit implements multi-file schema handling in the Prisma Schema Language. At a high level, instead of accepting a single string, `psl::validate_multi_file()` is an alternative to `psl::validate()` that accepts something morally equivalent to: ```json { "./prisma/schema/a.prisma": "datasource db { ... }", "./prisma/schema/nested/b.prisma": "model Test { ... }" } ``` There are tests for PSL validation with multiple schema files, but most of the rest of engines still consumes the single file version of `psl::validate()`. The implementation and the return type are shared between `psl::validate_multi_file()` and `psl::validate()`, so the change is completely transparent, other than the expectation of passing in a list of (file_name, file_contents) instead of a single string. The `psl::validate()` entry point should behave exactly the same as `psl::multi_schema()` with a single file named `schema.prisma`. In particular, it has the exact same return type. Implementation ============== This is achieved by extending `Span` to contain, in addition to a start and end offset, a `FileId`. The `FileId` is a unique identifier for a file and its parsed `SchemaAst` inside `ParserDatabase`. The identifier types for AST items in `ParserDatabase` are also extended to contain the `FileId`, so that they can be uniquely referred to in the context of the (multi-file) schema. After the analysis phase (the `parser_database` crate), consumers of the analyzed schema become multi-file aware completely transparently, no change is necessary in the other engines. The only changes that will be required at scattered points across the codebase are the `psl::validate()` call sites that will need to receive a `Vec<Box<Path>, SourceFile>` instead of a single `SourceFile`. This PR does _not_ deal with that, but it makes where these call sites are obvious by what entry points they use: `psl::validate()`, `psl::parse_schema()` and the various `*_assert_single()` methods on `ParserDatabase`. The PR contains tests confirming that schema analysis, validation and displaying diagnostics across multiple files works as expected. Status of this PR ================= This is going to be directly mergeable after review, and it will not affect the current schema handling behaviour when dealing with a single schema file. Next steps ========== - Replace all calls to `psl::validate()` with calls to `psl::validate_multi_file()`. - The `*_assert_single()` calls should be progressively replaced with their multi-file counterparts across engines. - The language server should start sending multiple files to prisma-schema-wasm in all calls. This is not in the spirit of the language server spec, but that is the most immediate solution. We'll have to make `range_to_span()` in `prisma-fmt` multi-schema aware by taking a FileId param. Links ===== Relevant issue: prisma/prisma#2377 Also see the [internal design doc](https://www.notion.so/prismaio/Multi-file-Schema-24d68fe8664048ad86252fe446caac24?d=68ef128f25974e619671a9855f65f44d#2889a038e68c4fe1ac9afe3cd34978bd).
This is awesome @janpio, thank you! Our own schema file is at almost 1,500 LOC now, so we'd love a split. =) If it's helpful from a design perspective, just wanted to request the ability for schema files to be split up across separate folders too, not necessarily all in one. We organize our codebase how the OP here described:
(And we've been finding that extremely nice and helpful.) Thanks again! |
No with react native support this makes even more sense if someone decides to share schema between backend and react native app |
Create a folder called models in your prisma folder, then add our files to it:
config.prisma
user.prisma
The merging step.
We change the current dir
|
I found this somewhere. |
seems like the wait is just about over PR Huge thanks to all the developers for their efforts on this. Been stalking the pull requests on this and it seems to have been quite the undertaking |
Hey, we just released support for multiple-file Prisma Schema setups! It is behind the
Please try it out and leave feedback in this discussion: #24413 |
Problem
Prisma currently only supports one single Prisma Schema file. Developers want more flexibility for managing their Prisma Schema files.
Motivations:
Solution
Support importing additional schema files, i.e.
import "user.schema"
,import models/*.prisma
orimport modules/**/*.prisma
.Alternatives
Not researched at this time.
Additional context
#92
The text was updated successfully, but these errors were encountered: