Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
iwasrobbed opened this issue Feb 22, 2024 · 0 comments
Open
2 tasks done

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

iwasrobbed opened this issue Feb 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@iwasrobbed
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • 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 iwasrobbed added the bug Something isn't working label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant