Prisma
This quickly shows how to connect your Prisma application to Supabase Postgres. If you encounter any problems, reference the Prisma troubleshooting docs.
If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), turn it off in the API Settings.
Create a custom user for Prisma
- In the SQL Editor, create a Prisma db-user with full privileges on the public schema.
- This gives you better control over Prisma's access and makes it easier to monitor using Supabase tools like the Query Performance Dashboard and Log Explorer.
password manager
For security, consider using a password generator for the Prisma role.
Create a Prisma Project
Create a new prisma Project on your computer
Create a new directory
Initiate a new Prisma project
Add your connection information to your .env file
- Visit the Database Settings
- Find your Supavisor Session Mode string. It should end with 5432. It will be used in your
.env
file.
If you're in an IPv6 environment or have the IPv4 Add-On, you can use the direct connection string instead of Supavisor in Session mode.
- If you plan on deploying Prisma to a serverless or auto-scaling environment, you'll also need your Supavisor transaction mode string.
- The string is identical to the session mode string but uses port 6543 at the end.
In your .env file, set the DATABASE_URL variable to your connection string
Change your string's [DB-USER]
to prisma
and add the password you created in step 1
Create your migrations
If you have already modified your Supabase database, synchronize it with your migration file. Otherwise create new tables for your database
Create new tables in your prisma.schema file
commit your migration
Install the prisma client
Install the prisma client and generate its model
Test your API
Create a index.ts file and run it to test your connection