Hello! Would someone be able to provide me an exam...
# orm-help
r
Hello! Would someone be able to provide me an example of adding a second schema Prisma using prisma-util? For example, I would like access to this table public.table1 and access to schema2.table1 by adding the correct settings in prisma-util.config.json. Currently the connection I have setup only has access to the database's public schema and I need to access other schemas. Thanks!
🆘 1
👀 1
v
i would be interested in this feature/docs as well especially to maintain auth users
r
@ven v - I was provided some previous documentation that can achieve this; however, the docs are not super detailed. You can use this - https://github.com/DavidHancu/prisma-util instead of prisma and enable the experimental feature
"crossFileRelations": true
in the
prisma-util.config.json
file that is generated when you run
npx prisma-util init
If you figured it out or get further than I did, I would love to hear how you did it 🙂
v
👍
r
and this is where they list support for experimental features (on the client side) https://www.prisma.io/docs/concepts/components/preview-features/client-preview-features
v
thank you for sharing all that
r
np
Looks like it only supports Postgres and MSSQL at the moment. @Prisma - Any idea if and when cockroach will be supported? Can I just use Postgres for now?
👀 1
v
👋 Hey @Ryan Roline, I'm checking with the Product team to see if this is on the roadmap or if there is anything else we can recommend. In the meantime, can I ask if this is for the same commercial web app you were referring to here?
d
Hi @Ryan Roline! If I understand correctly, you want to add multiple schemas to your Prisma Util config? If that's the case, you need to: 1. Setup your baseSchema to link to the file that contains your generator and datasource. 2. Add all of the other files in includeFiles. After this, the files will be merged into one. However, if you want to remap relations, (what it looks like to me), could you provide your schemas and what relations you want to remap? It would be easier to assist you this way.
For instance, if you have a table named Table1 defined in the file
schema.table1
and the column test of Table2 from
test.table2
uses a relation for Table1, you can remap the relation using the configuration file. Initial data:
schema.table1
Copy code
model Table1 {
   id Int @id @default(autoincrement())
   tableName String
}
test.table2
Copy code
model Table2 {
   id Int @id @default(autoincrement())
   tableId Int
   table Table1 @relation(fields: [tableId], references: [id])
}
You can add the following lines in your configuration file:
Copy code
"relations": {
   "test.table2:Table2.table": "schema.table1:Table1"
}
If you have an IDE extension that complains about Table1 not being a model in your
test.table2
file, you can create a "polyfill" or an empty Table2 model and it will automatically get replaced. Hope I helped!
I'd also like to thank you for the feedback on the documentation and I'll try to improve it by adding more examples, the cross-file relations are the hardest part to configure right now and it's not explained really well, so that's my fault.