Planetscale integration broken on branch deploy only

I have set up Planetscale integration, and it works with my production deployment. However, it fails with branch deployments.

{"errorMessage":"request to https://undefined/psdb.v1alpha1.Database/Execute failed, reason: getaddrinfo ENOTFOUND undefined","errorType":"FetchError","level":"error"
//...

Note the “undefined” in the URL.

The function is simple:

import { withPlanetscale } from "@netlify/planetscale";

exports.handler = withPlanetscale(async function (event, context) {
    const {
        planetscale: { connection },
    } = context;

    var dbDump = await connection.execute("SHOW TABLES");
    console.log(dbDump);
    
    return {
        statusCode: 200,
        body: JSON.stringify({
            message: dbDump
        })
    };
});

When I first enabled the integration, all of the PLANETSCALE_foo environment variables were missing a value for branch deploys. Here’s an example of what my dashboard looked like.
image
This might be an artifact of, when I set it up, not having a separate database yet for development.

However, I went back to Planetscale, made a development branch of the database, then disabled the netlify integration and re-enabled it. I now have values filled in for all the environment variables, but the problem persists.

Note that my site is new, so I am not using the legacy environment variable experience. My site is at https://starchatter.netlify.app/ and the branch deploy is at https://customize--starchatter.netlify.app/ although right now, they are in sync.

How can I get this working with branch deploys?

Hey!

Thanks so much for raising this, I’ve got this logged internally and will hopefully get something working this week or early next.

We’re putting thought into how branch deploys should work with PlanetScale, do we want a one-size fits all like for deploy previews or per-branch values.

It’s a problem we wanted to solve with feedback once in beta, however the fact there is no value at all is indeed a bug.

1 Like

Thanks for looking into it, looking forward to a response. For now, I guess I am have to develop on production.

Hello! Any new info on this? The forum bot is nudging me to ask.

So sorry for taking a while to get back!

We’re currently working through adding flows for branch-deploys across our integrations, PlanetScale being the first stop which should be done for the end of next week.

In the meantime, deploy previews and local development (via netlify dev) are both supported really well so you shouldn’t have any issues.

For now, I guess I am have to develop on production.

I am really interested by this, could you expand a bit on your workflow as to why deploy previews or local development aren’t sufficient here? Just so I can ensure you’re represented properly in our discussions internally.

1 Like

Luckily I am pre-launch, so it’s not the biggest deal, but I would like to change that soon. But here’s my experience. This is my first time working with Netlify so apologies if I have missed something important. I’m a pro game dev with a bunch of other experience including big chunks of the web stack, but web is not my typical day to day, so there may be gaps in my understanding there.

The features/integrations I’m using are:

  • Functions (both JavaScript and TypeScript)
  • branch deploy for development (haven’t done this in a while because of the issue in first post)
  • Netlify Identity
  • Planetscale database
  • Project based on your Next.js template
  • Local netlify command-line interface, running netlify dev to host

To be honest I have had a number of problems. I found that production is pretty stable, but the branch deploys and local hosting are not.

  • The bug in my first post is a blocker to using Planetscale, which is essential for most of my API.
  • I noticed that if I push a local tsconfig.json, it causes my functions to not be able to locate some files relative to the project root. I’ve excluded it in .gitignore.
  • Just now I tried running netlify dev and the compiler is complaining about all the imports using ‘@’. For example:
    image
    This does not occur on my main branch deploy. I tried removing tsconfig.json locally, but this did not help. This wasn’t always happening, though; I just got it now when I was trying stuff out for this writeup.
  • I had a lot of problems connecting to Netlify Identity using netlify dev also. This might be due to my browser tracking settings. Was able to do it in Chrome but not Firefox. Firefox works fine on my main deploy. Can’t test it now due to the above ‘@’ imports issue.
  • I remember a few other things blocking me from using branch/local builds, but they’re hard to dig up now because of the above blockers. I know that’s not terribly helpful - I will try to update when I get past them.

If you guys are doing a call or something and would like me to participate I can probably do work that in. I’d also be willing to give 2 of your devs access to my GitHub repo for now, if that would help, provided you agree to not leak anything about the project’s inner workings.

Thanks for working with me on this!

I have an update: I’ve manually copied and pasted all the values into the correct deploy contexts for each of the Planetscale-related environment variables and I’m now able to access my DB branch from a branch deploy!

Hey @hungy-angy,

Great news about being able to finally get this working!

However, I noticed you mentioned above that you’ve been struggling with various different issues with CLI or branch deploys. If you need help with any of those, feel free to open a separate topic so as to not add to this unrelated topic.

1 Like