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
Hi.
I have a legacy MySQL database. When I introspect a whole database I getting the error Error: Command failed with exit code 7 (E2BIG): /usr/local/lib/node_modules/prisma2/query-engine-darwin cli --dmmf_to_dml. Okay...
But I want to introspect and work with only several tables in my DB. Am I able to?
Reacted by Josias Iquabius, Irakli Safareli, Dami Izolan, Patrick Siegle, Doug Ludlow, Yunus Szönyi, Omar Dulaimi, Ghiath, Quentin Luc, Kay and 10 more
Not out of the box - but that is an interesting request. How do you imagine this could work?
Obviously the proper fix here is to make E2BIG go away and you being able to just introspect the whole database - but I can not give you any ETA on that. Please make sure to share as much information as possible so we can reproduce your specific problem.
As a workaround, you could create a copy of your database and get rid of the parts you think are causing the problem or you are not actually interested in. Introspection also just needs the schema, not the data - so creating a schema only copy should not be too hard.
Re 2) That means you use the param from 1) once, and the next time it picks up on the existing models in your Prisma schema and only looks at those again to create a new schema, correct?
+1 on this, when using another migration tool like knex it would be nice to be able to prevent the client code for the migrations and migrations_lock tables from being generated.
Supply list of tables to be introspected (only look at those)
Supply list of tables to be ignored (to not look at those)
Simplest solution: additional params to connection string, comma joined string of table names. E.g. &only_tables=foo,bar or &ignore_tables=fizz,buzz.
Complication: What happens with foreign keys to tables that are excluded?
Internal Note: Having this feature could be a perfect escape hatch for all the cases where we can not make Prisma work with some existing tables of bigger schemas.
Would it make more sense to have a config file rather than appending to the connection string? It would allow more fine grained control, and can be expanded for future use cases beyond just the topic of this issue. It would be super helpful to allow the the introspection and model generation process run with defaults and without configuration, but also allow overriding of specific behavior when the need arises.
Ignore tables.
Define table name to model name mappings
Define relationship names, for instance when a users table refers to itself should the relation be called users, parents, children etc. Same goes for relationships to other tables.
Pivoting through tables where there is no defined foreign key.
Read only models based on views
Polymorphic table configuration which can be a thing when migrating from another ORM.
Reacted by Dami Izolan, DL Redden and Jack Tomaszewski
Best open a new issue for this @jcloutz-radix - many (actually: all) of those are great suggestions, but clearly out of scope for this specific problem this issue is about.
For the "Introspecting part of a database" usecase the connection string might be enough, for those others we definitely want to have more configuration. (Link to this issue in the new one, so we make the connection between the both of them). Thanks!
@joeldarling - would it be sufficient for you to be able to split the prisma schema between multiple files? That way you could have your normal clean schema file, and another one called ignoredTables.prisma that looks like this:
model TableWeDontCareAbout { @@ignore }
model AnotherTableWeDontCareAbout { @@ignore }
@sorenbs that's actually how I have it now... as I decide a need a certain table, I move it from my "ignore" file to main schema file. Of course now, whenever I run introspect, it plops in all the models I don't want.
Being able to ignore those tables in the first place would be nice. The approach you mentioned would be fine
How is this feature request going? It's been more than 2 years since this discussion started and it would be really useful to be able to ignore some tables.
Reacted by Cheng Zheng(郑诚), Maël Mayon, Dexter Miguel, usagisagi, Gezim Hoxha, Lukas , Jack Tomaszewski, Chris Marx, Alexandre Rodriguez and lycpan233
If it works for someone else, I've been able to only introspect certain tables from my SQL Server DB by creating a user and granting access (select, insert, update, delete and alter) to the tables I'm working with. Then, in the connection string that Prisma uses, I specify the DB, user, and password I'm using. When I do an instrospect it only pulls the tables with the granted access.
Reacted by Lucas Pereira , Phil Efstathiou, Nicolas Vargas, Drew Hamlett, usagisagi, Aidan Rypens, Stas Makarov and Gabriele Toselli
Activity
janpio commentedon Oct 21, 2019
Not out of the box - but that is an interesting request. How do you imagine this could work?
Obviously the proper fix here is to make
E2BIGgo away and you being able to just introspect the whole database - but I can not give you any ETA on that. Please make sure to share as much information as possible so we can reproduce your specific problem.As a workaround, you could create a copy of your database and get rid of the parts you think are causing the problem or you are not actually interested in. Introspection also just needs the schema, not the data - so creating a schema only copy should not be too hard.
INovozhilov commentedon Oct 22, 2019
It could be:
janpio commentedon Oct 22, 2019
Thanks, we will take those into consideration.
Re 2) That means you use the param from 1) once, and the next time it picks up on the existing models in your Prisma schema and only looks at those again to create a new schema, correct?
INovozhilov commentedon Oct 22, 2019
yeah. This is my suggestion.
INovozhilov commentedon Oct 22, 2019
I checked another workaround, and it's work for me now. I created a new Mysql user and granted only needed tables — a not big overhead.
janpio commentedon Oct 23, 2019
Ohh, that i a great idea! With the "limited" user the introspection works fine?
(cc @nikolasburk - as this might be a useful workaround to document as long as we have these limitations)
nikolasburk commentedon Oct 23, 2019
Thanks a lot for sharing this @INovozhilov 💡 I added this workaround to the docs: https://www.prisma.io/docs/concepts/components/introspection#introspecting-only-a-subset-of-your-database-schema
INovozhilov commentedon Oct 23, 2019
Yes. With a restricted user, introspection works as designed.
jcloutz-radix commentedon Dec 9, 2019
+1 on this, when using another migration tool like knex it would be nice to be able to prevent the client code for the migrations and migrations_lock tables from being generated.
janpio commentedon Dec 15, 2019
Rough feature outline:
Simplest solution: additional params to connection string, comma joined string of table names. E.g.
&only_tables=foo,baror&ignore_tables=fizz,buzz.Complication: What happens with foreign keys to tables that are excluded?
Internal Note: Having this feature could be a perfect escape hatch for all the cases where we can not make Prisma work with some existing tables of bigger schemas.
jcloutz-radix commentedon Dec 16, 2019
Would it make more sense to have a config file rather than appending to the connection string? It would allow more fine grained control, and can be expanded for future use cases beyond just the topic of this issue. It would be super helpful to allow the the introspection and model generation process run with defaults and without configuration, but also allow overriding of specific behavior when the need arises.
janpio commentedon Dec 17, 2019
Best open a new issue for this @jcloutz-radix - many (actually: all) of those are great suggestions, but clearly out of scope for this specific problem this issue is about.
For the "Introspecting part of a database" usecase the connection string might be enough, for those others we definitely want to have more configuration. (Link to this issue in the new one, so we make the connection between the both of them). Thanks!
8 remaining items
sorenbs commentedon Apr 26, 2021
@joeldarling - would it be sufficient for you to be able to split the prisma schema between multiple files? That way you could have your normal clean schema file, and another one called
ignoredTables.prismathat looks like this:joeldarling commentedon May 27, 2021
@sorenbs that's actually how I have it now... as I decide a need a certain table, I move it from my "ignore" file to main schema file. Of course now, whenever I run introspect, it plops in all the models I don't want.
Being able to ignore those tables in the first place would be nice. The approach you mentioned would be fine
jiaranda commentedon Feb 24, 2022
How is this feature request going? It's been more than 2 years since this discussion started and it would be really useful to be able to ignore some tables.
arieljr10699 commentedon Nov 2, 2022
If it works for someone else, I've been able to only introspect certain tables from my SQL Server DB by creating a user and granting access (select, insert, update, delete and alter) to the tables I'm working with. Then, in the connection string that Prisma uses, I specify the DB, user, and password I'm using. When I do an instrospect it only pulls the tables with the granted access.
Baldrani commentedon Aug 22, 2023
Has anybody solved that problem for PostgreSQL ? I've tried to REVOKE privileges for a specific user, but it's not enough.
jtomaszewski commentedon Feb 7, 2024
I've just used https://github.com/MrLeebo/prisma-ast to parse the introspected schema file, add ignore attributes to any models or relations than are not on my "allowed model names" list, and output the schema file.
So now generating the prisma file looks like this to me:
Here's the source code of the
add-ignore-decorators.tsscript for those interested:erw13n commentedon Feb 23, 2024
Hi @jtomaszewski nice share.
I just got to many tables and need drop that not being used. Just be careful with relation.
igalklebanov commentedon Dec 26, 2025
Hey 👋
Closing this for being dusty and stale.