can anyone help? trying to use subscription in van...
# javascript
s
can anyone help? trying to use subscription in vanilla nodejs, status is subscribed and replication is enabled for all tables, subscription status is subscribed but i don't get any updates
Copy code
supabase
    .from("*")
    .on("*", (payload) => {
      console.log("change", payload)
    })
    .subscribe(console.log)
    .onError((e) => console.log("error", e))
g
can anyone help? trying to use subscription in vanilla nodejs, status is subscribed and replication is enabled for all tables, subscription status is subscribed but i don't get any updates
Copy code
supabase
    .from("*")
    .on("*", (payload) => {
      console.log("change", payload)
    })
    .subscribe(console.log)
    .onError((e) => console.log("error", e))
Do you have RLS on for selects? Try with off on a table if so. What are you using for key or jwt?
s
rls is disabled and i'm using the service_role key
g
This has come up for several people with service role. Not seen an absolute solution, plus different environments and seems go away without a clear solution....
With RLS off, even if you were getting a JWT instead of service_role, it should go thru. Are you on latest drivers and probably restart your supabase instance.
s
i already tried restarting the supabase instance 😅 what do you mean by latest drivers?
it's the first time trying it today
i'm also using prisma, could that be a problem?
g
Ugg on prisma...
Seen several issues with that and permissions on schema and tables which would impact realtime possibly.
s
yeah, i've seen that too, is there an easy way to duplicate a database in supabase?
g
I'm full of good news, no... you have to run from a terminal basically and copy out and load back. There are discussion on that here.
s
alright, ill try a fresh project and check if prisma has to do something with it
thank you so far!
g
You can also look at table realtime.subscription and see if there is data there. The claims column there with a subscription running gives a clue on how the subscription connected.
s
Copy code
{
  "exp": 1961489816,
  "iat": 1645913816,
  "iss": "supabase",
  "ref": "wanoglxvccpkkvocajjf",
  "role": "service_role"
}
the entities are wrapped with
""
, is that normal?
g
realtime.subscription normally looks like this.
s
yeah, mine looks wrong:
g
That is realtime.subscription table? Does it have columns labeled like mine? If that is really the correct table I'm talking about I vote for prisma being the issue somehow.
s
yep, it's the table
with
the same columns
do you have experience with the typed js client? https://github.com/bnjmnt4n/supabase-client
is it advanced enough to use it? if yes, i'll just ditch prisma
g
Oh wait. on your table, it is the claim column that is important. I just realized those are your table names, so that part looks fine for the first 4 columns.
On your supabase-client thing. If the code has not been updated since Jan time frame it likely will not work with realtime as that was changed extensively this year. On that client it does not have realtime anyways at a quick glance.
s
that's not the client i'm using
g
Understand, you just asked about though.
s
yeah i just asked about it, because i'm missing the generated client if i'm not using prisma
i'm using the official supabase client
but just for subscriptions
g
realtime.js or supabase.js
s
supabase.js
g
So you may not be getting any claims/tokens as supabase.js does stuff with keys and tokens and passes them to realtime.js. You might be able to just use realtime.js
s
okay, will try that
thanks!
g
If your realtime.subscription had nothing in claims column then points that way.
s
i have this in the claims column
{"exp":1961489816,"iat":1645913816,"iss":"supabase","ref":"wanoglxvccpkkvocajjf","role":"service_role"}
and the claims role is
service_role
g
I don't have service_role anymore in my code for testing, but that actually seems correct, if I recall. Unfortunately with prisma in the picture I'm not much help, but in general service role does work as long as replication switches are on and then each table is checked. You might start a new topic mentioning prisma or search around on that with realtime.
s
okay, ill just test a new project without prisma
thank you for the help 🙂
g
Post back if you find something, as many of these just get dropped or magically work again....
s
yep, will do
it works fine with a fresh project on supabase, i'll try to add prisma now and check when it breaks
g
capture your realtime.subscription table before if you can.
s
soo... it somehow works now
even with prisma
but on a new database
but i didn't migrate
that might have been a problem, i just pushed with prisma
i'm not that experienced with prisma, so i don't really know what's happening there
g
Prisma users seem to sometime have permission issues on schemas when they do "what ever you prisma users do" with the Supabase tables. Sorry I've just seen the issues and questions, but know nothing about Prisma. If you search here or github discussions it seems to take some care to get it to work.
s
yep that's gonna be it, im going to investigate more, but it's good to know that prisma is the issue here
g
Unless you need Prisma 😂
s
yeah, but i think i can still manage to use prisma, just not every feature 😄
yep, i just used migrate and now the subscriptions don't work anymore
g
I generated a general issue on this as it should be known at least... https://github.com/supabase/supabase/issues/5685
s
@User i commented on the issue, the privileges look different on prisma created tables vs tables created in the dashboard
g
Hey if you get a chance try turning replication on a single table with Prisma permissions on, then go to the database log under settings. I see: statement: BEGIN; ALTER PUBLICATION supabase_realtime SET TABLE public.test6,public.test,public.test4,public.test5,public.realtest,public.messages; ALTER PUBLICATION supabase_realtime SET (publish = 'insert,update,delete'); COMMIT; and the user doing it is supabase_admin. I would think "he" should still have ability to do that as a superuser but "he" is not listed in your Prisma set up table is one difference
s
Copy code
statement: BEGIN; ALTER PUBLICATION supabase_realtime SET (publish = 'insert,update,delete,truncate'); COMMIT;
Copy code
statement: BEGIN; ALTER PUBLICATION supabase_realtime SET TABLE public."Tournament"; ALTER PUBLICATION supabase_realtime SET (publish = 'insert,update,delete,truncate'); COMMIT;
g
So replication seems to succeed even if supabase_admin is not in the privileges (which I sort of expected as a superuser) . I'm going to leave to those in the know on realtime/prisma table permissions at this point. Certainly seems like realtime is not getting some permission it needs with a Prisma generated table.
s
what could i use to replace realtime for now? you think triggers would work? @User
g
What do you need to do with realtime? Triggers don't help much unless you are passing changes to a status table not impacted by Prisma, and still monitored by realtime. Polling every few minutes or so is OK in debug, but not good for volume if a whole table.
s
i need realtime to react on changes on a specific table
i guess i have to wait until someone can help me with the issue
g
If you want you could look at replica setting on a prisma table:
Copy code
select relreplident from pg_class
where relname = 'table';
it should be "d" for default which means it will use it's primary key (I assume Prisma has a primary key) or "f" for full which uses all the columns for replication. You could also try this if it is not full, incase there is some strange primary key thing going on ALTER TABLE your_table REPLICA IDENTITY FULL;
s
it was d, i set it to f, still doesn't work 😦
g
Yeah, I'm just trying to guess what Prisma might set different. You could look at database log after you change a record and see if something errors I guess.
s
if you look at the permission thing i posted in github, on the dashboard created table it is
.../supabase_admin
but on the prisma generated table it is
.../postgres
, what does that mean?
i also do not get any errors anywhere, it's really hard to debug this problem 😅
g
the supabase_admin versus postgres is just who assigned the other user the permission. Prisma (and any other DBM using the external connection) are assigned postgres user. postgres is powerful, but not a full superuser like supabase_admin.
s
ahhh, got it
okay uhhh, i somehow got it to work
i'm gonna update the issue
g
I hate those "I somehow got it to work" solutions... have seen several of those with realtime and combined and separately with prisma.
s
but that's all i got 😅 but the problem still persists, supabase should throw an error if something is wrong with real time and I think that should be fixed/improved
it's also not a solution 😄
i also don't want to fiddle with the databases anymore, i just wanted to try supabase, now i can finally proceed with the actual app i wanted to write 😅
g
I'm hoping they expose the log at some point. Evidently realtime has it's own log (and it is huge) but can only seen from file system. Feel free to ping me when you get further down the road with realtime stuff. I've been spending alot of time working on reliability of it and how to actually use it in the "real world".
s
will do!
it doesn't work for a single table... 😦
g
I'm out for the night, but do you mean it does not work at all for tables, or you have one table that does not work?
s
sorry, i have one table that doesn't work
g
OK try the ALTER TABLE your_table REPLICA IDENTITY FULL on it just in case it does not have a primary key. Double check it is toggled on in the UI, I have had many times the toggle does not take when I'm sure I toggled it.
Luck!
s
didn't help, oh well, i'm done for now 😅