sambecker / exif-photo-blog

Photo blog, reporting 🤓 EXIF camera details (aperture, shutter speed, ISO) for each image.
https://photos.sambecker.com
736 stars 130 forks source link

Option to use any other Postgres #75

Closed kylemclaren closed 5 months ago

kylemclaren commented 5 months ago

Hi, love this app!

I am deploying it on not Vercel, so I'd like to be able to use Supabase instead of Vercel Postgres. My understanding is this is supported in the SDK: https://vercel.com/docs/storage/vercel-postgres/sdk#createclient

Kicking this off in case others have a workaround to offer, but ultimately it would be nice to have the option to set a DATABASE_URL for any other PG and it Just Works™️

When I try to set POSTGRES_URL and POSTGRES_URL_NON_POOLING to my Supabase instance, I get:

VercelPostgresError - 'invalid_connection_string': This connection string is meant to be used with a direct connection. Make sure to use a pooled connection string or try `createClient()` instead.

Also, see https://github.com/orgs/supabase/discussions/14165 and https://github.com/vercel/storage/issues/123

sambecker commented 5 months ago

Hi Kyle, would love to be able to support this. Will size up the effort and report back. So glad you're into the app!

sambecker commented 5 months ago

Ok, did some digging/prototyping and it seems like there aren't reliable drop-in pg replacements that work on Vercel's edge runtime, which is used heavily throughout the template. Even Supabase's recommended approach of appending ?workaround=supabase-pooler.vercel to the POSTGRES_URL connection string crashed/hanged for me when deployed (confusingly, it seems to work locally).

One potential solution could be to switch all functions to nodejs in the presence of a Supabase-preferred configuration, but I'd want users to be aware of the trade-off they're implicitly making.

Will keep thinking on this.

kylemclaren commented 5 months ago

Thanks for looking at this, Sam! I tried that same workaround — it also crashed. I think it's related to the @neondb/serverless driver:

NeonDbError: Server error (HTTP status 404): Not Found

More than that I don't yet know — but I'll keep exploring this and post back here if I get any further.

sambecker commented 5 months ago

After some final testing, it doesn't feel viable to move this app off the edge runtime to support a different database.

Closing this for now, though there's a good chance—with the right optimizations—that this template will eventually migrate to Node.js. Should that happen, will definitely revisit this issue!

sambecker commented 5 months ago

Now that the app uses the Node.js runtime, this was fairly straightforward to implement in #86

@kylemclaren let me know if this works for your use case

kylemclaren commented 5 months ago

@sambecker Awesome! Will try this out asap

sambecker commented 5 months ago

Merged!

kylemclaren commented 5 months ago

Awesome @sambecker I tried to test this branch but hit some weird issue where my ENV vars are not being read — possibly related to moving away from the edge runtime. I am investigating elsewhere, but appreciate the work that went into this PR!

sambecker commented 5 months ago

Can you post some of your issues/errors @kylemclaren?

I have a project currently connecting to Supabase in prod and it seems to work fine. What specifically are you seeing?

kylemclaren commented 5 months ago

Well, my env vars are definitely set and present on the VM, but I still see:

Screenshot 2024-05-03 at 18 20 02

I didn't want to raise it here as I am running this app on Fly.io and not Vercel — so it was something I wanted to figure out on the Fly side first. Will test on Vercel next.

sambecker commented 5 months ago

Ok—good to know!

If no configuration's showing up, sounds like this isn't an issue specific to Postgres/Supabase?

kylemclaren commented 5 months ago

Correct! I'll close this out.

kylemclaren commented 5 months ago

Quick update here @sambecker — tested with Supabase (after figuring out my ENV issues) and looks to be working just fine.

sambecker commented 5 months ago

Amazing! Thanks for confirming.