https://supabase.com/ logo
#javascript
Title
# javascript
s

ShooTeX

02/26/2022, 11:18 PM
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

garyaustin

02/26/2022, 11:46 PM
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

ShooTeX

02/26/2022, 11:48 PM
rls is disabled and i'm using the service_role key
g

garyaustin

02/26/2022, 11:51 PM
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

ShooTeX

02/26/2022, 11:53 PM
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

garyaustin

02/26/2022, 11:54 PM
Ugg on prisma...
Seen several issues with that and permissions on schema and tables which would impact realtime possibly.
s

ShooTeX

02/26/2022, 11:56 PM
yeah, i've seen that too, is there an easy way to duplicate a database in supabase?
g

garyaustin

02/26/2022, 11:57 PM
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

ShooTeX

02/26/2022, 11:58 PM
alright, ill try a fresh project and check if prisma has to do something with it
thank you so far!
g

garyaustin

02/26/2022, 11:58 PM
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

ShooTeX

02/27/2022, 12:02 AM
Copy code
{
  "exp": 1961489816,
  "iat": 1645913816,
  "iss": "supabase",
  "ref": "wanoglxvccpkkvocajjf",
  "role": "service_role"
}
the entities are wrapped with
""
, is that normal?
g

garyaustin

02/27/2022, 12:05 AM
realtime.subscription normally looks like this.
s

ShooTeX

02/27/2022, 12:05 AM
yeah, mine looks wrong:
g

garyaustin

02/27/2022, 12:08 AM
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

ShooTeX

02/27/2022, 12:08 AM
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

garyaustin

02/27/2022, 12:10 AM
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

ShooTeX

02/27/2022, 12:14 AM
that's not the client i'm using
g

garyaustin

02/27/2022, 12:14 AM
Understand, you just asked about though.
s

ShooTeX

02/27/2022, 12:14 AM
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

garyaustin

02/27/2022, 12:15 AM
realtime.js or supabase.js
s

ShooTeX

02/27/2022, 12:16 AM
supabase.js
g

garyaustin

02/27/2022, 12:17 AM
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

ShooTeX

02/27/2022, 12:17 AM
okay, will try that
thanks!
g

garyaustin

02/27/2022, 12:18 AM
If your realtime.subscription had nothing in claims column then points that way.
s

ShooTeX

02/27/2022, 12:20 AM
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

garyaustin

02/27/2022, 12:26 AM
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

ShooTeX

02/27/2022, 12:27 AM
okay, ill just test a new project without prisma
thank you for the help 🙂
g

garyaustin

02/27/2022, 12:28 AM
Post back if you find something, as many of these just get dropped or magically work again....
s

ShooTeX

02/27/2022, 12:34 AM
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

garyaustin

02/27/2022, 1:45 AM
capture your realtime.subscription table before if you can.
s

ShooTeX

02/27/2022, 1:53 AM
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

garyaustin

02/27/2022, 2:04 AM
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

ShooTeX

02/27/2022, 2:06 AM
yep that's gonna be it, im going to investigate more, but it's good to know that prisma is the issue here
g

garyaustin

02/27/2022, 2:06 AM
Unless you need Prisma 😂
s

ShooTeX

02/27/2022, 2:07 AM
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

garyaustin

02/27/2022, 2:32 AM
I generated a general issue on this as it should be known at least... https://github.com/supabase/supabase/issues/5685
s

ShooTeX

02/27/2022, 4:59 PM
@User i commented on the issue, the privileges look different on prisma created tables vs tables created in the dashboard
g

garyaustin

02/27/2022, 5:24 PM
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

ShooTeX

02/27/2022, 5:28 PM
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

garyaustin

02/27/2022, 5:35 PM
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

ShooTeX

02/27/2022, 5:48 PM
what could i use to replace realtime for now? you think triggers would work? @User
g

garyaustin

02/27/2022, 5:49 PM
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

ShooTeX

02/27/2022, 7:29 PM
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

garyaustin

02/27/2022, 9:46 PM
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

ShooTeX

02/27/2022, 11:49 PM
it was d, i set it to f, still doesn't work 😦
g

garyaustin

02/28/2022, 12:00 AM
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

ShooTeX

02/28/2022, 12:12 AM
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

garyaustin

02/28/2022, 12:20 AM
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

ShooTeX

02/28/2022, 12:25 AM
ahhh, got it
okay uhhh, i somehow got it to work
i'm gonna update the issue
g

garyaustin

02/28/2022, 1:56 AM
I hate those "I somehow got it to work" solutions... have seen several of those with realtime and combined and separately with prisma.
s

ShooTeX

02/28/2022, 1:57 AM
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

garyaustin

02/28/2022, 2:03 AM
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

ShooTeX

02/28/2022, 2:04 AM
will do!
it doesn't work for a single table... 😦
g

garyaustin

02/28/2022, 4:52 AM
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

ShooTeX

02/28/2022, 4:56 AM
sorry, i have one table that doesn't work
g

garyaustin

02/28/2022, 4:58 AM
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

ShooTeX

02/28/2022, 5:02 AM
didn't help, oh well, i'm done for now 😅