supabase / realtime

Broadcast, Presence, and Postgres Changes via WebSockets
https://supabase.com/realtime
Apache License 2.0
6.81k stars 314 forks source link

Supabase realtime in own database - error relation "tenants" does not exist #809

Open VitorBrangioni opened 8 months ago

VitorBrangioni commented 8 months ago

Bug report

Describe the bug

Hello guys,

I was using Supabase realtime in my own database in 2 years ago. So now, I'd like to upgrade my supabase realtime version. I'm trying to update it, but i'm receiving "relation 'tenants' does not exist ". I have my own database, I don't like to change anything there or migrate to a supabase database. How can I fix it? I would like just listen postgres changes...

I'm spending long time trying to figure out it.

Thank you for helping me.

Screen Shot 2024-03-16 at 15 24 02
filipecabaco commented 7 months ago

I think it might be related with the move to a multi tenant approach meaning that now you will need to run a migration ( mix ecto.migrate ) and then you will need to run a PUT request:

curl -v -X PUT \
  'http://localhost:4000/api/tenants/<tenant_id>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer < API_JWT_SECRET > \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "tenant": {
    "db_host": "localhost",
    "db_port": 6432,
    "db_database": "postgres",
    "ip_version": "v4",
    "require_user": true,
    "upstream_ssl": false,
    "enforce_ssl": false,
    "default_max_clients": 200,
    "default_pool_size": 1,
    "extensions": [],
    "jwt_secret": "secret",
    "users": [
      {
        "db_user": "postgres",
        "db_password": "postgres",
        "mode_type": "transaction",
        "pool_checkout_timeout": 100,
        "pool_size": 1
      }
    ]
  }
}'

Please do change the data according to your needs.

AntonOfTheWoods commented 5 months ago

@filipecabaco do you happen to know if this is actually documented in any formal sense? I find it rather curious that the only admin/setup documentation would be the docker-compose.yaml files they provide but that definitely seems the only thing the supabase team is willing to provide, at least as open source...

And you mention <tenant_id> above. Is that documented anywhere? If you are running realtime locally, then presumably tenant_id is not something supabase the SAAS service is going to provide, right?

filipecabaco commented 4 months ago

You are right that this lacks proper documentation, that is something we definitely should improve!

As for the value tenant_id it could be any value, not related to anything on the supabase side and the configuration could be any postgres database.

I will work on adding better documentation on the self hosting side. It also crossed my mind that it would be useful to have some sort of admin mode when using self hosted 🤔 do you think that would be useful?

AntonOfTheWoods commented 4 months ago

What would be useful is the bare minimum of documentation that is expected of any open source project. I know "scratch an itch" and all that but documentation and error messages are special cases. I also utterly reject the notion that Supabase the company doesn't have internal documentation for most of this. For project after project I have had to go and dig into the source to understand what config is required and that is just absolutely NOT the way to manage any sort of SAAS offering! Many of the subprojects are no longer "fast moving" so there is not even that excuse...

Supabase seems to provide most of the executable code but to call it "open source" is a misnomer IMHO!

filipecabaco commented 4 months ago

The reality is that we indeed have the same docs and they are truly lacking even on our side, the repo you see is exactly what we have, everything else are automations based on openapi docs that are publicly available ( https://realtime.supabase.co/swaggerui ) and faster feedback loops since we are more readily available to reply.

Again, this is truly something we need to work on and fix in this repository so we improve the overall experience for self hosted but also internally.

AntonOfTheWoods commented 4 months ago

Ok, well thanks for the honesty! But if that is really the case then someone needs to take the CEO aside and give him a stern talking to... maybe there is an important investor who could do it? All it would require is making it part of your merge workflow (e.g, is this new thing documented, in the same way as you have "is this new thing tested"...) and having someone taking the "docs fascist" job title for a few months to ensure compliance and this issue would disappear.

Your stuff evolves relatively quickly (yay!) but then you get REQUIRED stuff added like

"ssl_enforced": true/false,

On the "tenant" that simply doesn't appear to be documented anywhere (public, though granted you probably have a private exchange on a slack channel somewhere...), and causes hard-to-diagnose errors (because the error messages aren't wonderful...).

Again, if you were using something in a super-popular language like java/go/c/python/js, etc then you can be a little more lax but having no docs, non-brilliant error messages and using a very marginal language like erlang makes trying to debug stuff like this horrible. And though I'm not 100% certain, it appears that there are bugs in the examples integrated into the code... but because there are no docs and I don't know elixir, I can't really tell...

filipecabaco commented 4 months ago

We're finishing some features to then revamp the docs completely as the biggest item in our roadmap as we already identified it as a big pain and causing big issues. Plus that will also give us the opportunity to improve the self hosting docs as they are also lacking at the moment.

Also recently we've revamped a lot of our errors to be more user friendly and we will keep doing it as we go.

Thank you for the feedback and keeping this in check as indeed is an area we're currently subpar and that we need to improve

AntonOfTheWoods commented 4 months ago

Great news! I will be here to nitpick and help out if I can! :)

filipecabaco commented 4 months ago

Please do! I will probably create a discussion in Supabase repository ( https://github.com/orgs/supabase/discussions ) under the general section so we can track feedback and contributions easily.

Already added this issue to the current internal doc so we can refer to it and leave a comment here when we start this work (should be within the next couple of weeks I hope)