Is Prisma DB Pull reliable?
stuck while running prisma db push or pull
Ecto equivalent for "prisma db pull"?
prisma db pull doesn't see a new table - Stack Overflow
My backend is a fastify/Prisma to a PostgreSQL DB, I am much more comfortable with building my DB tables and constraints (PK, FK, etc) via SQL rather than Prisma's relationships schema.
My question is: If I continue to build my DB architecture directly in the db, is the Prisma db pull a reliable method to keep my Prisma schema up to date and accurate so I can get the typing's?
I just am able to comprehend and explain the relationship much better via SQL rather than via the model references.
I had a similar issue once and a quick check confirmed for me that it was the lack of security permissions granted for prisma on new table in the database itself.
Try this:
- Note the name of the database user that Prisma connects to the database with. You'll likely find this via your schema.prisma file, or perhaps via a
DATABASE_URLconfig setting in the related.envfile if you're using that with prisma. - Go into the database itself and ensure that database user which Prisma connects with has been granted sufficient security privileges to that new table. (note: what 'sufficient' is I cannot say since it depends on your own needs. At a guess, I'd say at least 'select' permission would be needed.)
- Once you've ensure that user has sufficient privileges, try running a
prisma db pullcommand once again.
For reference, another thing you could do is:
- cross-check against one of the other tables that is already in your database that works correctly with prisma.
- compare the security privileges of that old table with the security privileges of the new table and see if there are any differences.
If you use supabase and running this command and it returns something like this 'The following models were commented out because we couldn't retrieve columns for them. Please check your privileges.' or something similar regarding privileges, the solution is to go to your SQL editor from supabase and put this command and execute it
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO postgres;