Replies: 2 comments
-
|
Hey @enciso, sorry for the delayed response! I replied in the Discord thread a while back but then completely forgot to follow up here with actual details. Good news: You found a real bug! The However, the auto-derivation approach won't work because the URLs are fundamentally different: It's not just a port change - the hostname, username format, AND region all differ. From the direct URL you can extract:
The region (e.g., Why transaction pooler is required: EdgeWorker needs pooled connections because Edge Functions can be killed at any time. Direct connections would be left hanging, exhausting your connection pool quickly. The fix: Once I fix the EdgeWorker.start(MyFlow, {
connectionString: Deno.env.get('MY_CUSTOM_POOLER_URL'),
});For preview branches: Unfortunately, you'll need to get the pooler URL from each preview branch's dashboard (Settings -> Database -> Connection string -> Transaction pooler) and set it as an env var. There's no way to auto-derive it. Risky alternative: Once the bug is fixed, you could technically use EdgeWorker.start(MyFlow, {
connectionString: Deno.env.get('SUPABASE_DB_URL'),
});But I strongly advise against this - direct connections from serverless workers can quickly exhaust your connection pool, and I can't provide support for issues arising from this approach. The transaction pooler exists for good reason. Would you be able to test the fix once it's ready? |
Beta Was this translation helpful? Give feedback.
-
|
Update: I checked with the Supabase team - exposing the pooler URL or database region is a known gap they've discussed internally. For now, manually setting the pooler URL is the only option, but it's on their radar. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When using Supabase Preview Branches, each preview branch has its own database URL. Currently,
EDGE_WORKER_DB_URLmust be set as a static environment variable, which prevents connecting to the correct preview branch database dynamically.This is only a problem for preview branches - production/main branch works fine! ✨
What I Want to Do
I want to derive the pooler connection string from
SUPABASE_DB_URL(which is already available and branch-aware):Why It Doesn't Work
SupabasePlatformAdapterrequiresEDGE_WORKER_DB_URLas a mandatory environment variable during initialization:Even if I provide
connectionStringin the worker config:context.sqlin handlers uses the env var connection, not the config oneThe Solution I'm Hoping For
Make
EDGE_WORKER_DB_URLoptional whenconnectionStringis provided in config, or auto-derive it fromSUPABASE_DB_URL.Priority:
connectionStringin worker config (explicit override)EDGE_WORKER_DB_URLenv var (backwards compatibility)SUPABASE_DB_URL→ convert:5432/to:6543/This way preview branches can automatically connect to their branch-specific database!
Why This Matters
SUPABASE_DB_URLis already available and branch-aware:5432/→:6543/)Current workaround: Manually set
EDGE_WORKER_DB_URLper branch, which doesn't scale.Related Files
pkgs/edge-worker/src/platform/SupabasePlatformAdapter.ts- Validation logicpkgs/edge-worker/src/EdgeWorker.ts- Worker startuppkgs/edge-worker/src/core/workerConfigTypes.ts- Already documentsconnectionStringoptionCurrent workaround: I'm manually setting the env variable after preview creation, but it would be great if this could work automatically. I'd be happy to help with the implementation if needed!
Thanks! 🙏
Beta Was this translation helpful? Give feedback.
All reactions