Planetscale integration broken on Test branch

Hi my Netlify site in on riskgpt.io and test.riskgpt.io.

Using Planetscale has been very confusing until now, but I think I managed to cut through quite a lot to get to this last issue:

My function can’t connect to the test branch on PlanetScale. I have defined all env variables and am using WithPlanetScale, but it tries to run my queries again my production/main DB. I can re-factor to use DATABASE_URL but am thinking if I can get the context thing to work, that would save me effort and over time also set the base for a cleaner and more secure/stable code.

I got all env .variables set for the right DB contexts on Netlify and followed all integration steps (I connect to the DB and try and run queries…).

Is this a known issue? If so, is there a solution or at least a workaround?

Any help greatly appreciated.

Hey @agaziel2,

We’ve asked the devs to take a look.

1 Like

Changing to planetscale/database connect, as well as changing all credentials to test DB credentials in the env variables helped. If someone got context to really work, would be cool to know how. I actually don’t think it works or that I understand it enough.

Thanks for coming back and sharing how you got this working! The devs will update the thread with more context soon.

Great. Would love to get some feedback. I’m new to React/Netlify/Planetscale so will be awesome to learn more. Please also explain context, preferably with a couple of examples how it should work in a dev/test-prod setup.

Regards,
Avishay

Hey @agaziel2 ,

Sorry for the delayed response, but I’d love to try and help you out here.

So, the withPlanetscale higher-order function passes in a connection pre-configured from these environment variables.

    host: process.env.PLANETSCALE_HOST,
    password: process.env.PLANETSCALE_PASSWORD,
    username: process.env.PLANETSCALE_USERNAME,

Now, it was intended to be used in tandem with the UI documented here. However, there is no reason you can’t have these 3 environment variables set manually and use the withPlanetscale.

Is the test database you’re trying to connect to a branch on Planetscale, or is it it’s own separate database?

I kinda sorted it out (or at least found a workaround I can live with). The test db is a branch on PlanetScale.

Regards,
Avishay

thanks for sharing you found your solution!