zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 89 forks source link

[Bug] Delegate Model and Extended Model should support different db schema #1647

Open gattish opened 1 month ago

gattish commented 1 month ago

Currently: when creating a delegate model with a db schema (using @@schema), we cannot define the extended model's schema, it must be in the same schema. If I try to set the @@schema on the extended model, during generate I get error.

How it should: It would be a very good feature to have the possibility to put the extended model in a different db schema using the @@schema tag for extended models as well.

Use Case: when creating a multi-tenant setup with different schemas, the delegate model goes into "public" db schema, while the extended models are going into the individual "tenant" schemas. This way all the tenants have the same "base" table but different extended tables (and possibly different fields) in their own db schema.

Thank you, Attila

gattish commented 1 month ago

UPDATE: after investigating deeper it seems it is a bug, not a feature request. When generating with "zenstack generate" the prisma schema file is created but on the extended model both "@@schema" tag is added which is wrong. The delegated model "@@schema" tag is also added which should not be the case and that's why "prisma generate" cannot run but gives error.