realtime icon indicating copy to clipboard operation
realtime copied to clipboard

[Broken] Custom primary keys (nanoids) breaks realtime listeners

Open iwasrobbed opened this issue 2 years ago • 3 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When using nanoids as a primary key on a real-time table—instead of the default uuidv4 values—it breaks all real-time functionality on that table in various ways (see below).

To Reproduce

  1. Add a script like this to migrations to generate nanoids as primary keys https://gist.github.com/iwasrobbed/a537ddb745d313904fa7188e4dd82a68
  2. Configure a real-time table to use those nanoids as primary keys (e.g. id char(21) PRIMARY KEY DEFAULT generate_nano_id() NOT NULL)
  3. Notice how the real-time listeners break (e.g. inserts no longer get called and for deletes it trims the id down to a single char versus showing the full 21 chars)

Expected behavior

Real-time should be agnostic to the type of primary key as long as it's a valid SQL primary key type

Screenshots

In the below delete callback, it trimmed the old id down to a single character (regardless of if it starts with a number or letter) when the original id was a 21 character nanoid

CleanShot 2024-02-22 at 15 25 34@2x

System information

  • OS: macOS
  • Browser (if applies): Arc
  • Version of supabase-js: ^2.39.3
  • Version of Node.js: v21.6.2

Additional context

Switching back to uuidv4 as primary keys immediately resolved the issue, but is not ideal for indexing.

iwasrobbed avatar Feb 22 '24 20:02 iwasrobbed

I also have problem with NanoID. It only detects table changes if I DELETE, not INSERT or UPDATE. Have you find a solution for it? Thanks!

rexhibition avatar Aug 03 '24 00:08 rexhibition