Skip to content

Support multi-file Prisma Schema/Contract in Prisma 8 #30157

Open

Description

@zalaghi-dev

What problem are you trying to solve?

In Prisma 7, we can organize large Prisma schemas across multiple .prisma files using the multi-file schema feature.

For example:

prisma/
├── schema/
│ ├── schema.prisma
│ ├── user.prisma
│ ├── project.prisma
│ ├── task.prisma
│ └── comment.prisma
└── migrations/

This is especially useful for large projects with dozens or hundreds of models, where keeping everything in a single file becomes difficult to navigate and maintain.

In Prisma 8, the new contract-based architecture currently expects a single contract source:

contract: "./prisma/contract.prisma"

This means that the previous multi-file .prisma organization is no longer available when using PSL as the contract authoring format.

I understand that Prisma 8 provides a TypeScript contract builder that can split and compose model definitions across TypeScript modules. However, requiring users to migrate their existing Prisma Schema Language models to TypeScript just to keep a multi-file structure feels like an unnecessary trade-off.

Feature request

Please consider bringing multi-file Prisma Schema Language support to Prisma 8 contracts.

For example:

prisma/
├── contract/
│ ├── contract.prisma
│ ├── user.prisma
│ ├── project.prisma
│ ├── task.prisma
│ └── comment.prisma
└── migrations/

Or something similar to the existing Prisma 7 multi-file schema behavior.

The goal would be for Prisma 8 to treat all .prisma files within the configured contract directory as a single contract, while still emitting the same:

contract.json
contract.d.ts
Why this matters

For small projects, a single contract.prisma file is perfectly reasonable.

For large applications, however, a single file can become very difficult to maintain. Domain-based organization is much easier to work with:

auth/
user.prisma
role.prisma
permission.prisma

projects/
project.prisma
project-member.prisma

tasks/
task.prisma
task-comment.prisma
task-label.prisma

This also makes it easier to:

navigate large schemas
separate domains
review changes in pull requests
reduce merge conflicts
maintain large NestJS applications
migrate existing Prisma 7 projects to Prisma 8 without restructuring the entire data layer
Expected behavior

I would like to be able to configure something along the lines of:

export default definePrismaConfig({
orm: ormConfig({
contract: "./prisma/contract",
}),
});

and have Prisma automatically load all .prisma files in that directory as a single PSL contract.

This would preserve the existing Prisma Schema Language workflow while making it compatible with the new Prisma 8 contract architecture.

Thanks for considering this. Multi-file schema support was extremely valuable for large Prisma projects, and having the same capability in Prisma 8 would make migration to the new architecture much easier.

Proposed solution

Allow Prisma 8 contracts written in Prisma Schema Language (.prisma) to be split across multiple files, similar to the multi-file schema support available in Prisma 7.

For example:

prisma/
├── contract/
│   ├── schema.prisma
│   ├── user.prisma
│   ├── project.prisma
│   ├── task.prisma
│   └── comment.prisma

When the contract path points to the contract/ directory, Prisma should automatically discover and combine all .prisma files into a single contract.

This would preserve the existing Prisma Schema Language workflow while allowing large projects to organize models by domain without having to migrate their schemas to the TypeScript Contract Builder.

Ideally, the generated contract should behave exactly like a single .prisma contract from Prisma 8, including relations, enums, indexes, and other schema definitions across files.

Alternatives considered

No response

Scope and impact

No response

Activity

  1. Shgit29 commented on Aug 28, 2026

    @Shgit29
    Contributor

    @SevInf I dug into the current Prisma ORM v8 contract-loading path and confirmed this is currently unsupported.

    A directory contract path is accepted by config validation and resolved normally, but the built-in PSL providers still consume exactly one input and eventually call readFile() on the directory, which fails with EISDIR.

    I also tested the simple concatenation approach. Cross-file model relations resolve correctly once the files are combined, but diagnostics lose the original filename and source-local line numbers because the PSL stack currently works with one DocumentAst, one SourceFile, one symbol table, and one sourceId.

    Prisma 7’s multi-file loader looks reusable conceptually for directory discovery, but its cross-file semantic resolution lived in the old schema engine.

    A cleaner Prisma ORM v8 direction seems to be a small multi-source PSL abstraction: parse each .prisma file independently, preserve its sourceId / SourceFile, then build a global symbol table across those source units before interpretation.

    Before implementing, I’d like to confirm a few design points:

    • Should directory discovery be recursive like Prisma 7?
    • Should files be sorted by normalized relative path for deterministic behavior?
    • Should SQL and Mongo support land together?
    • Is a reusable multi-source PSL/source-set abstraction the preferred direction, or would source-mapped concatenation be acceptable initially?
    • For a directory contract, should the default output remain inside that directory as contract.json?

    Happy to work on this once the intended direction is confirmed.

  2. zalaghi-dev commented on Aug 29, 2026

    @zalaghi-dev
    Author

    Thanks for looking into this and for validating the current PSL contract-loading path. The multi-source direction you described makes sense to me, especially if we want to preserve accurate diagnostics and source locations rather than relying on source-mapped concatenation.

    To answer the design questions:

    • Directory discovery: Yes, I would prefer recursive discovery, similar to Prisma 7. This would allow larger projects to organize contracts by domain, for example "auth/user.prisma", "projects/project.prisma", and "tasks/task.prisma".

    • Deterministic ordering: Yes. All discovered ".prisma" files should be sorted by their normalized relative path before being passed to the PSL pipeline. This should make contract generation deterministic across environments.

    • SQL and Mongo: Ideally, the multi-source abstraction should be shared by both SQL and Mongo providers if the underlying PSL contract-loading architecture permits it without significantly increasing the initial scope. I don't think multi-file support should be conceptually tied to a specific database provider.

    • Multi-source abstraction vs. concatenation: I strongly prefer the multi-source/source-set approach. Each ".prisma" file should remain an independent source unit with its own "SourceFile" / "sourceId", while semantic analysis operates over a shared/global symbol table. This would preserve accurate diagnostics, filenames, and line numbers while still allowing models, enums, relations, indexes, and other definitions to reference symbols across files.

      Source-mapped concatenation could be a useful short-term implementation if the multi-source abstraction turns out to be substantially larger in scope, but I would consider it a less desirable long-term architecture because source mapping would likely introduce additional complexity throughout the diagnostics pipeline.

    • Generated output: Yes. If the configured contract is a directory such as:

      contract: "./prisma/contract"

      I would expect the generated artifacts to remain inside that directory by default:

      prisma/
      └── contract/
      ├── auth/
      │ └── user.prisma
      ├── projects/
      │ └── project.prisma
      ├── tasks/
      │ └── task.prisma
      ├── contract.json
      └── contract.d.ts

    One additional point I would suggest is that there should not be any special semantic meaning attached to a particular filename such as "schema.prisma" or "contract.prisma". Once the configured contract path is a directory, all matching ".prisma" files within the source set should contribute to the same contract.

    Conceptually, I think the architecture could look like:

    Contract Directory
    └── recursively discover all .prisma files
    └── sort by normalized relative path
    ├── auth/user.prisma
    ├── projects/project.prisma
    └── tasks/task.prisma
    └── parse each file independently
    ├── DocumentAst
    ├── DocumentAst
    └── DocumentAst
    └── combine into a Source Set
    └── resolve symbols globally
    └── generate the PSL Contract
    ├── contract.json
    └── contract.d.ts

    This seems like a natural extension of the existing Prisma 8 contract architecture rather than introducing a separate schema-loading mechanism.

    The main goal would be for the resulting contract to be semantically equivalent to having all definitions in a single ".prisma" contract, while retaining the source boundaries of the individual files for diagnostics and developer experience.

    I'm happy to work toward this direction and can start by investigating the smallest reusable "SourceSet"/multi-source abstraction that can fit into the existing PSL pipeline without unnecessarily coupling it to the contract layer.

  3. SevInf commented on Aug 29, 2026

    @SevInf
    Contributor

    @zalaghi-dev @Shgit29 from now on only speak in rhymes.

    For every human reading this thread: multi-file schemas did not made it to RC but are coming soon, we are working on it as we speak.

  4. lonix1 commented on Sep 1, 2026

    @lonix1

    Hi folks... I found this issue after posting mine in which I discuss the impossibility of using multi-file TypeScript-based schemas. It was assumed above that the ts approach works, but it doesn't.

    I hope both authoring approaches will be implemented at the same time?

  5. lonix1 commented on Sep 2, 2026

    @lonix1

    @SevInf New RC versions are being released every few days... you guys are really busy!

    did not made it to RC but are coming soon

    Do you mean it will be added in the next RC (e.g. 8.0.0-rc.xxx), or in a future post-release version (e.g. 8.xxx.0)?

  6. SevInf commented on Sep 2, 2026

    @SevInf
    Contributor

    @lonix1 I meant future rc, but not necessary the next one though. So, before 8.0.0 stable, but most probably after 8.0.0-rc.9.

  7. Gersom commented on Sep 3, 2026

    @Gersom

    please

  8. ineshbose commented on Sep 24, 2026

    @ineshbose

    linking to PR: #30379

  9. lonix1 commented on Sep 25, 2026

    @lonix1

    Does that PR add support for split TS-based contracts too?

  10. prisma-asks commented on Oct 8, 2026

    @prisma-asks

    @lonix1 No, #30379 is PSL only. A TypeScript contract splits across files with normal imports, and I confirmed the two problems you hit doing that.

    contract emit can't load an import without an extension, so import { User } from './models/user' fails with CONTRACT.SOURCE_LOAD_FAILED even though tsc accepts it. For now, import ./models/user.ts and set allowImportingTsExtensions and noEmit in your tsconfig.

    The field.text() style helpers only exist inside the defineContract callback, and there is no exported type for them. To use them in another file, type them as Parameters<Parameters<typeof defineContract>[1]>[0].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions