Supabase and Prisma workflow compilation #7659
Replies: 3 comments 9 replies
-
Thanks for this important documentation of flaws and bugs! This prevented me from embarking onto a long integration journey that probably would have just made me miserable and when I look at all the bugs/flaws that come from the increased complexity. I'd be great if supabase had a simple schema like Prisma (feat wink). |
Beta Was this translation helpful? Give feedback.
-
I've been playing with Prisma and Supabase lately and really the only way I was able to get it "working" is by:
Things I tried that did not work, as of late 2022:
There were some problems with this. When running a However the migrations had errors:
This seems fixable, but when thinking about it, maybe it's best to be considering Supabase's auth schema as "internals" and to not have to be syncing that a
You might be able to do this by creating a new DB user as per: https://www.prisma.io/docs/concepts/components/introspection#introspecting-only-a-subset-of-your-database-schema Overall I just feel like the whole Prisma and Supabase experience is disjointed as it stands. I was hoping to have everything working in the Some code that might be helpful, Trigger mentioned in (2):
|
Beta Was this translation helpful? Give feedback.
-
Were you able to fix the db error: ERROR: schema "auth" does not exist error? |
Beta Was this translation helpful? Give feedback.
-
Note: This is a updated copy from the discord's
help
channel to increase visibility. I hope this can also be a central source for pointing to Prisma issues and workaround. Cross-posted to prisma/prisma#14292 for Prisma's side.Edit: For others having same issue, I recommend Subscribing for notifications in case I/someone else update the thread with a guide in the future.
Edit 2: Short answer: Hard setup. Slight to no hiccups after.
Hello! Has anyone successfully implemented Prisma to work with Supabase? It would be great if I could draw some insights on whether implementing Prisma has been worth it. I have been reading this past week on trying to get them to work together meeting several issues with workarounds.
No cross schema (Support querying across multiple schemas prisma/prisma#1122).
auth.users
cannot be accessed (Issues cross-referencing tables from different schemas using Prisma #1502). We need to use a trigger to update apublic.users
table. Integrating with prisma with support for local development and RLS #4051 (comment)prisma.$queryRawUnsafe('SELECT * FROM auth."users"')
usingpostgres
role by sb on discord. https://discord.com/channels/839993398554656828/1009277878736785439/1009668643065438208Creating that trigger in
1
requires a separate script run ourselves viapsql
(easy to forget or make mistakes). Integrating with prisma with support for local development and RLS #4051 (comment)Using any function like
auth.id()
requires a "fake" functionpublic.auth_id()
to be used in-place, then replaced viapsql
like2
. Integrating with prisma with support for local development and RLS #4051 (reply in thread)Incrementing ID primary key doesn't work .
id BigInt @id @default(autoincrement())
does not create auto increment properly. Bug: Constraints not well-handled by Studio #7560Grants are a bit messed up when resetting db during dev https://supabase.com/docs/guides/integrations/prisma#troubleshooting
Required to create a separate db user to not bypass RLS and to give grants Supporting session-dependent queries like Postgres'
SET
across queries of a request prisma/prisma#5128 (comment) Prisma database introspection #838 (comment)Required to use a Prisma middleware to inject the
current_user_id
for each transactions (with no official documentation on this, only other users' code) Supporting session-dependent queries like Postgres'SET
across queries of a request prisma/prisma#5128 (comment) OR implement helper for RLS Supporting session-dependent queries like Postgres'SET
across queries of a request prisma/prisma#5128 (comment)We cannot add other schemas like the
supa-audit
extension which uses theaudit
schema. Need to apply manually.Current issues with quotes in name Prisma migration with Quoted Types breaks realtime. #5685 (comment)Fixed Prisma migration with Quoted Types breaks realtime. #5685 (comment)Use separate connection string for migrate vs normal use with PgBouncer (supabase already provides this) https://supabase.com/docs/guides/integrations/prisma#connection-pooling-with-supabase (for deployment: https://community.redwoodjs.com/t/guide-migrations-connection-pool-urls-supabase/2505)
RLS has to be manually created unlike in Supabase where we can Supabase Studio Supporting session-dependent queries like Postgres'
SET
across queries of a request prisma/prisma#5128 (comment)Telemetry? Set
CHECKPOINT_DISABLE=1
Extensions schema not seen by Prisma. Need to
CREATE SCHEMA IF NOT EXISTS "extensions"; CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA extensions;
for UUID Local Development - Using Extensions #2250 (reply in thread)Trigger issue with Prisma-created tables Error: "permission denied for schema public" when trying to use a trigger function on a table created by Prisma #7094 (comment)
Cannot migrate to Supabase hosted db (unclear, I do not have this issue) Prisma unable to connect to Supabase database #7772 Cannot connect to Supabase database prisma/prisma#13807
Cannot change role to
authenticated
without a bit of changes (My solution is mimicauthenticator
role with our ownprisma
role OR reverting to use deprecatedauth.role
)Using RLS with Prisma opens a hole in our db where users can connect directly via Postgrest and bypass our API. (My solution: use our own
authenticated
role)Need to run
psql
in CI to prevent mix-matching env. However, CI env does not usually havepsql
available. Solutions I have found: 1. run a Github Actions CI (installing postgres andpsql
) to run build, push, migrate, andpsql
. 2. Manually and carefully run thepsql
comands from personal computer once. It should only require once and any other time need to cross-schema stuff.Prisma Migrate only helps with schema-related SQL. For Supabase migrate, you could work on db then pull. My solution: write the pure SQL on
.sql
file thenmigrate reset
till it works for you. Recommend have aseed
script. Requires more familiarity with SQL.Windows Prisma timeout with Supabase as reported by balabanshik (https://discord.com/channels/839993398554656828/1034600133121277972/1034603713807011940). Their fix was to add longer
connect_timeout
.Using
camelCase
convention could break db. Usesnake_case
instead. https://discord.com/channels/839993398554656828/885237287280070708/988097402059780098Up to this point, I am sure I have not discovered all the nitty gritty bugs still. Does anyone have any opinion or experience to share about using Prisma? I will also consolidate this info to one place to help future people facing these issues.
Beta Was this translation helpful? Give feedback.
All reactions