Hey there, Nikolas from Prisma here! 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? This is definitely a valid approach! I think a lot of people prefer writing their own migrations (using whatever tool they prefer for that) and then use Prisma's introspection to update their Prisma schema — the main thing to be aware of with that workflow is that you need to run npx prisma generate after each introspection run to make sure the generated Prisma Client types and API get updated. This is also covered in the docs as a typical Prisma workflow: SQL migrations and introspection Answer from nikolasburk on reddit.com
🌐
Prisma
prisma.io › home › prisma cli reference › prisma cli reference › prisma cli reference
Prisma CLI reference | Prisma Documentation
<glob> is a placeholder for a glob ... data loss. The db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema....
🌐
Prisma
prisma.io › home › pull › pull › pull
prisma db pull | Introspect Database to Prisma Schema | Prisma Documentation
The prisma db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.
Discussions

prisma db pull doesn't see a new table - Stack Overflow
I have existing schema for prisma. I copied the table from another schema to be included in the Prisma schema. But when I run prisma db pull new table doesn't appear in Prisma schema. Why? More on stackoverflow.com
🌐 stackoverflow.com
when i do command 'npx prisma db pull', Can i pull specific table?
i have many unnecessary tables,, So, i want to pull specific tables when i do npx prsima db pull. is there functions? PrismaJoinThe official Discord server of Prisma! More on answeroverflow.com
🌐 answeroverflow.com
July 10, 2024
database - Why "npx prisma db pull" is blocked on Introspecting? - Stack Overflow
hello I want to add a table in my database (supabase). So I add this in supabase. And when I try to pull my table (from database supabase) with npx prisma db pull for uptdate prisma schema the comm... More on stackoverflow.com
🌐 stackoverflow.com
Ecto equivalent for "prisma db pull"?
Once nice thing about Prisma is you can connect to an existing database, and use the CLI to run “prisma db pull” - and then it uses introspection on the database to build a nice model file. The thing that is not as nice, is then the models are prisma models, not Ecto schemas 🙂 Is there ... More on elixirforum.com
🌐 elixirforum.com
7
0
September 23, 2024
🌐
Reddit
reddit.com › r/node › is prisma db pull reliable?
r/node on Reddit: Is Prisma DB Pull reliable?
August 14, 2023 -

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.

🌐
GitHub
github.com › prisma › prisma
GitHub - prisma/prisma: Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB · GitHub
Prisma Tests Status: Scheduled CI is currently disabled across the ORM repos; test workflows run on push, pull request, and manual workflow_dispatch.
Starred by 47.4K users
Forked by 2.4K users
Languages   TypeScript 99.0% | JavaScript 0.9% | Shell 0.1% | Dockerfile 0.0% | PLpgSQL 0.0% | Batchfile 0.0%
Top answer
1 of 3
2

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_URL config setting in the related .env file 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 pull command 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.
2 of 3
1

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;
Find elsewhere
🌐
GitHub
github.com › prisma › prisma › discussions › 12792
Is there a way to migrate after pulling existing database without loosing data? · prisma/prisma · Discussion #12792
April 13, 2022 - mkdir -p prisma/migrations/init npx prisma migrate diff --preview-feature --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/init/migration.sql npx prisma migrate resolve --applied init npx prisma migrate dev # it should say everything is in sync
Author   prisma
🌐
MCP Servers
mcpservers.org › home › agent skills library › prisma-cli-db-execute
prisma-cli-db-execute | Agent Skills Library
prisma-cli-db-pull · by prisma · prisma-cli-db-pull — an installable skill for AI agents, published by prisma/cursor-plugin. prisma-cli-db-push · by prisma · prisma db push.
🌐
Answer Overflow
answeroverflow.com › m › 1260417605471174767
when i do command 'npx prisma db pull', Can i pull specific ...
July 10, 2024 - i have many unnecessary tables,, So, i want to pull specific tables when i do npx prsima db pull. is there functions? PrismaJoinThe official Discord server of Prisma!
Top answer
1 of 3
4

Some prisma CLI commands(ex: npx prisma db pull) require DIRECT_URL to be passed as part of datasource object like below.

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}

You can read about it more here: Prisma Datasource fields

The Direct Url uses Session Mode URL and connects via port:5432. Whereas Database URL uses Transaction Mode URL and connect via port:6543

Note: I'm using Supabase, which is a PostgreSQL database.

2 of 3
0

I just fired up a new project to verify that this works:

npm init
npm install prisma --save-dev

Add .env file with database information, e.g.

DATABASE_URL="postgresql://postgres.xxxxyyyyzzzz:passpasspass@aws-0-us-west-1.pooler.supabase.com:5432/postgres?schema=public"

where postgres.xxxxyyyyzzzz is they user name, and passpasspass is the password

Then run

npx prisma init --datasource-provider postgresql

And finally:

npx prisma db pull

Which produces the prisma/schema.prisma file, first few lines:

/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model locations {
  location_name    String             @db.VarChar(255)
  street_address   String             @db.VarChar(255)
  city             String             @db.VarChar(100)
  state_province   String             @db.VarChar(100)
  postal_code      String             @db.VarChar(20)
  unit_number      String?            @db.VarChar(20)
  notes            String?
  id               String             @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  service_requests service_requests[]
}

Edit: Then I added a new table Foo, and ran npx prisma db pull again, adds the table to the schema

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model foo {
  id         BigInt   @id @default(autoincrement())
  created_at DateTime @default(now()) @db.Timestamptz(6)
}
🌐
GitHub
github.com › prisma › prisma › discussions › 15775
How can i pull or introspect a defined list tables · prisma/prisma · Discussion #15775
Hi @kaykhan 👋 It's not possible at the moment, npx prisma db pull will introspect all the database tables.
Author   prisma
🌐
Elixir Forum
elixirforum.com › questions & help › questions
Ecto equivalent for "prisma db pull"? - Questions - Elixir Programming Language Forum
September 23, 2024 - Once nice thing about Prisma is you can connect to an existing database, and use the CLI to run “prisma db pull” - and then it uses introspection on the database to build a nice model file. The thing that is not as nice, is then the models are prisma models, not Ecto schemas 🙂 Is there ...
🌐
GitHub
github.com › prisma › prisma › discussions › 26085
How to safely apply migration to old projects? · prisma/prisma · Discussion #26085
Introspect the Database: Use the prisma db pull command to introspect your existing database.
Author   prisma
🌐
Prisma
prisma.io
Prisma | Agent Infrastructure for TypeScript
Prisma Postgres gives you standard PostgreSQL with built-in pooling and support for modern deployment environments.
🌐
Fig
fig.io › manual › prisma › db › pull
prisma db pull | Fig
prisma db pull · prisma db push · prisma db seed · prisma db execute · prisma version · prisma version · prisma version --json · No description · On this page ·
🌐
Prisma
prisma.io › home › views › views › views › views
How to include views in your Prisma schema | Prisma Documentation
Support for views is currently a Preview feature. You can add a view to your Prisma schema with the view keyword or introspect the views in your database schema with db pull. You cannot yet apply views in your schema to your database with Prisma Migrate and db push unless the changes are added ...
🌐
Prisma
prisma.io › home › schema api › schema api › schema api
Prisma Schema API | Prisma Documentation
When a mismatch is present, Prisma Migrate indicates a migration is still needed. You can use prisma db pull to infer the correct value to resolve the discrepancy.
🌐
Codú
codu.co › home › niall maher › pull schema from database in prisma
Pull Schema From Database in Prisma | by Niall Maher | Codú
February 21, 2024 - With Prisma you can pull the schema from your connected database by running: npx prisma db pull · This overwrites your current schema.prisma with the one it infers from your database.
🌐
YouTube
youtube.com › watch
Using the Prisma DB Pull Command - YouTube
Prisma 2.18 introduced a change to the way databases are introspected.Instead of using the `prisma introspect` command, developers should now use the `prisma...
Published   March 3, 2021
🌐
Prisma
prisma.io › home › getting started with prisma migrate › getting started with prisma migrate › getting started with prisma migrate
Getting started with Prisma Migrate | Prisma Documentation
bunx prisma db pull · Create a baseline migration that creates an initial history of the database before using Prisma migrate. This migrations contains the data that must be maintained, which means the database cannot be reset.