You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@hyochan we've updated the schema spec with a concrete syntax proposal to support importing from other .prisma files. You can see the spec here.
I've copied over the snippet for convenience. I'd love to hear your thoughts whether this is what you're looking for or whether you have other suggestions/requirements. 🙏
schema.prisma
import "./post.prisma"
model User {
posts Post[]
}
post.prisma
model Post {
title String @pg.varchar(42)
body String
}
Reacted by Nelson Pecora, Miklos, Michał Chmura, Hossein Saniei, Harshit Pant, Thomas Marrec, elliscwc, Siroj Inadias, Kevin Labory, Martin Eboh and 15 more
Since the schema is global anyway, why not do it the v1 way and include multiple prisma files in the config and maybe even supporting globs? This should also be easier to implement, as the files just have to be joined together, no import/parsing/require/resolve stuff needed. I also think that with a huge schema it can get cumbersome to import several types, especially considering that the IDE/editor can't parse and help with those imports (for now I guess).
So we're not planning on re-introducing the prisma.yml file for Prisma 2 because we want to have the option to consolidate all the Prisma-related configuration into one file. Given this constraint, we're left with the following options:
Pass in schema file paths / globs via the CLI everywhere we need the schema (basically every command)
Introduce Go-style imports where folders gets concatenated together. We'd also need someway to bring in base schemas from other folders.
Introduce a import "user.schema" to the schema.
It also ties into a discussion about explicit vs. implicit. Go's packages follow an implicit concatenation rule vs. something like Node.js where you explicitly include files via require("./myfile").
post/video.prisma, post/picture.prisma, post/text.prisma would all be joined as 1 schema without any additional syntax, so you can reference models and types within the post/ as if it's in one file.
We'd still probably need to introduce syntax to support things like base.prisma importing the post package.
schema.prisma
import"./post"
Which would pull in the models from the whole ./post directory.
In addition to what @matthewmueller mentioned above, would it be possible to support doing the import in the format of a node glob string?
For example, if I were to organize my code into separate folders with one model per file:
models/person.prisma
models/address.prisma
...
Or into feature-specific "modules" directory of some sort:
Then in the root schema.prisma file, it would be nice to be able to pull in all of the *.prisma files using a glob string such as: import models/*.prisma or import modules/**/*.prisma
We have over 400 tables so splitting them out and then importing them with a single glob string would be ideal.
Reacted by Luca Steeb, Matt Mueller, Anh Le, elliscwc, Daniel Berry, Rafael Kraut, shynome, Christoph Dietrich, Guillaume P, Domagoj Vukovic and 6 more
Still no news regarding the development of this feature or an alternative?
I love everything that has been done on prisma2, i would really like to migrate 😞
Reacted by LF, Malcolm Nihlén, Siroj Inadias, Guillaume P, Jack Davies, yazer79, GG Nam, Yannick Tamburrini and Benjaminz
The links to the docs above seem to be broken, and I can't seem to find any info about this in the docs. Is there any other information on this anywhere?
Reacted by Siroj Inadias, Ilshat Khamitov, Lukas Böcker and Jack Davies
But if you ran the script 2x, you'd get duplicate entries and prisma format would complain.
This also doesn't work too well if you have the prisma VSCode extension b/c it'll complain that String[]: "The current connector does not support lists of primitive types" because of the missing datasource db provider.
@khuezy you need to use '>>' so that the files are combined. Otherwise they would overwrite each other. You'd prob want to delete the file first so that old entries are cleared. Also, if you run it and leave the schema VS should be happy I would think.
cat *.prisma > ../schema.prisma would combine all the .prisma content into a single schema.prisma file, so you wouldn't need to delete the schema.prisma file right? Or am I missing something.
I ended up moving all my models into a single schema.prisma until prisma adds support for separate files. I was still getting syntax errors in VSCode.
other method awk 1 ./prisma/schemas/*.prisma >> ./prisma/schema.prisma && npx prisma format
@deyvisonborges as already stated by @khuezy above you should use > instead of >> >> will append the output to an existing file. So if you run it 5 times you will have all models 5 times in your schema.prisma. > will "overwrite" the contents of schema.prisma <= this is what you want.
Activity
[-][Question] How to use multiple schemas in prisma[/-][+][Question] How to seperate prisma files to manage models[/+]pantharshit00 commentedon Jul 4, 2019
Hi,
It is in the datamodel spec: https://github.com/prisma/rfcs/blob/0002-datamodel-2/text/0002-datamodel.md#multiple-prisma-in-the-same-directory-get
However, this hasn't been implemented yet.
schickling commentedon Jul 9, 2019
@hyochan we've updated the schema spec with a concrete syntax proposal to support importing from other
.prismafiles. You can see the spec here.I've copied over the snippet for convenience. I'd love to hear your thoughts whether this is what you're looking for or whether you have other suggestions/requirements. 🙏
schema.prisma
post.prisma
steebchen commentedon Jul 31, 2019
Since the schema is global anyway, why not do it the v1 way and include multiple prisma files in the config and maybe even supporting globs? This should also be easier to implement, as the files just have to be joined together, no import/parsing/require/resolve stuff needed. I also think that with a huge schema it can get cumbersome to import several types, especially considering that the IDE/editor can't parse and help with those imports (for now I guess).
matthewmueller commentedon Jul 31, 2019
Hey @steebchen!
So we're not planning on re-introducing the
prisma.ymlfile for Prisma 2 because we want to have the option to consolidate all the Prisma-related configuration into one file. Given this constraint, we're left with the following options:import "user.schema"to the schema.It also ties into a discussion about explicit vs. implicit. Go's packages follow an
implicitconcatenation rule vs. something like Node.js where you explicitly include files viarequire("./myfile").Do you have any preference or thoughts on this?
HosseinAgha commentedon Jul 31, 2019
@matthewmueller could you explain how Go-style import work in this scenario?
matthewmueller commentedon Jul 31, 2019
@HosseinAgha yep, given this directory structure:
app/
post/video.prisma,post/picture.prisma,post/text.prismawould all be joined as 1 schema without any additional syntax, so you can reference models and types within thepost/as if it's in one file.We'd still probably need to introduce syntax to support things like
base.prismaimporting the post package.schema.prisma
Which would pull in the models from the whole
./postdirectory.jmadson commentedon Jul 31, 2019
In addition to what @matthewmueller mentioned above, would it be possible to support doing the import in the format of a node glob string?
For example, if I were to organize my code into separate folders with one model per file:
Or into feature-specific "modules" directory of some sort:
Then in the root
schema.prismafile, it would be nice to be able to pull in all of the*.prismafiles using a glob string such as:import models/*.prismaorimport modules/**/*.prismaWe have over 400 tables so splitting them out and then importing them with a single glob string would be ideal.
[-][Question] How to seperate prisma files to manage models[/-][+]Seperate prisma files to manage models[/+]Aperrix commentedon Dec 4, 2019
Still no news regarding the development of this feature or an alternative?
I love everything that has been done on prisma2, i would really like to migrate 😞
scriptcoded commentedon Dec 15, 2019
The links to the docs above seem to be broken, and I can't seem to find any info about this in the docs. Is there any other information on this anywhere?
12 remaining items
khuezy commentedon Mar 12, 2022
Thanks! Probably want to use the single ">" right? Otherwise it'll amend the same models on subsequent commands.
deyvisonborges commentedon Mar 13, 2022
@khuezy
>redirects output to a file, overwriting the file.>>redirects output to a file appending the redirected output at the end.khuezy commentedon Mar 13, 2022
But if you ran the script 2x, you'd get duplicate entries and
prisma formatwould complain.This also doesn't work too well if you have the prisma VSCode extension b/c it'll complain that
String[]: "The current connector does not support lists of primitive types" because of the missing datasource db provider.bdombro commentedon Mar 13, 2022
@khuezy you need to use '>>' so that the files are combined. Otherwise they would overwrite each other. You'd prob want to delete the file first so that old entries are cleared. Also, if you run it and leave the schema VS should be happy I would think.
khuezy commentedon Mar 13, 2022
cat *.prisma > ../schema.prismawould combine all the .prisma content into a singleschema.prismafile, so you wouldn't need to delete theschema.prismafile right? Or am I missing something.I ended up moving all my models into a single
schema.prismauntil prisma adds support for separate files. I was still getting syntax errors in VSCode.bdombro commentedon Mar 13, 2022
You may be right
deyvisonborges commentedon Mar 14, 2022
other method
awk 1 ./prisma/schemas/*.prisma >> ./prisma/schema.prisma && npx prisma formatRafaelKr commentedon Mar 15, 2022
@deyvisonborges as already stated by @khuezy above you should use
>instead of>>>>will append the output to an existing file. So if you run it 5 times you will have all models 5 times in your schema.prisma.>will "overwrite" the contents of schema.prisma <= this is what you want.There is a detailed description of output redirection: https://linuxhandbook.com/redirection-linux/
taylor-lindores-reeves commentedon Mar 23, 2022
@matthewmueller is this something in the pipeline?
btd1337 commentedon Jun 19, 2022
Nomia commentedon Jun 20, 2023
but, how do u relate each other if there is relation between in different files?
mdarifulislamroni521 commentedon Apr 28, 2024
Any official updates here?
janpio commentedon Apr 29, 2024
The feature request is being tracked here: #2377