Avatar for the prisma user
prisma
prisma-engines
BlogDocsChangelog

Experiment with multi-file schema handling in PSL

#4243Merged
Comparing
psl-multi-file-schema
(
3fee3aa
) with
main
(
3d92748
)
CodSpeed Performance Gauge
-5%
Improvements
0
Regressions
1
Untouched
10
New
0
Dropped
0
Ignored
0

Benchmarks

Failed

build (small)Regression
query-engine/schema/benches/schema_builder_bench.rs::benches::criterion_benchmark::schema_builder::build (small)
CodSpeed Performance Gauge
-5%
266.8 µs
281.5 µs

Passed

mutation
query-engine/request-handlers/benches/query_planning_bench.rs::benches::criterion_benchmark::mutation
CodSpeed Performance Gauge
-1%
6.2 ms
6.3 ms
small_read
query-engine/request-handlers/benches/query_planning_bench.rs::benches::criterion_benchmark::small_read
CodSpeed Performance Gauge
-2%
107.1 µs
109.2 µs
deep_read_query
query-engine/request-handlers/benches/query_planning_bench.rs::benches::criterion_benchmark::deep_read_query
CodSpeed Performance Gauge
-2%
1.9 ms
1.9 ms
validate (small)
query-engine/schema/benches/schema_builder_bench.rs::benches::criterion_benchmark::psl::validate (small)
CodSpeed Performance Gauge
-2%
1.7 ms
1.8 ms
validate (large)
query-engine/schema/benches/schema_builder_bench.rs::benches::criterion_benchmark::psl::validate (large)
CodSpeed Performance Gauge
-3%
52.1 ms
53.5 ms
validate (medium)
query-engine/schema/benches/schema_builder_bench.rs::benches::criterion_benchmark::psl::validate (medium)
CodSpeed Performance Gauge
-3%
11.6 ms
12 ms
medium_read
query-engine/request-handlers/benches/query_planning_bench.rs::benches::criterion_benchmark::medium_read
CodSpeed Performance Gauge
-4%
311.8 µs
323.2 µs
large_read
query-engine/request-handlers/benches/query_planning_bench.rs::benches::criterion_benchmark::large_read
CodSpeed Performance Gauge
-5%
1.6 ms
1.6 ms
build (large)
query-engine/schema/benches/schema_builder_bench.rs::benches::criterion_benchmark::schema_builder::build (large)
CodSpeed Performance Gauge
-5%
4.5 ms
4.8 ms
build (medium)
query-engine/schema/benches/schema_builder_bench.rs::benches::criterion_benchmark::schema_builder::build (medium)
CodSpeed Performance Gauge
-5%
2.2 ms
2.3 ms

Commits

Click on a commit to change the comparison range
Base
main
3d92748
-5%
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: https://github.com/prisma/prisma/issues/2377 Also see the [internal design doc](https://www.notion.so/prismaio/Multi-file-Schema-24d68fe8664048ad86252fe446caac24?d=68ef128f25974e619671a9855f65f44d#2889a038e68c4fe1ac9afe3cd34978bd).
1e42d35
2 years ago
by tomhoule
0%
Merge branch 'main' into psl-multi-file-schema
11925e2
1 year ago
by jkomyno
0%
chore(prisma-fmt): fix compilation after https://github.com/prisma/prisma-engines/pull/4137
3fee3aa
1 year ago
by jkomyno
© 2025 CodSpeed Technology
Home Terms PrivacyDocs