Skip to content

fix: fixes #4186#4192

Open
tairosonloa wants to merge 1 commit intoumami-software:masterfrom
tairosonloa:patch-1
Open

fix: fixes #4186#4192
tairosonloa wants to merge 1 commit intoumami-software:masterfrom
tairosonloa:patch-1

Conversation

@tairosonloa
Copy link
Copy Markdown
Contributor

@tairosonloa tairosonloa commented Apr 20, 2026

Some database providers, like supabase, provides two URLs to access the database. A main URL behind pgBouncer's for load balancing, and a direct separated URL to perform migrations (running DDL operations), as does not support advisory locks or multi-statement DDL required by migrations.

Before v3.1.0, adding directUrl along with url to prisma/schema.prisma was enought.

Now, I'm making a commit to use direct URL when set (env variable DIRECT_DATABASE_URL exists and is not empty). Otherwise, default to the already existing DATABASE_URL. This should work for all deployments, so it shouldn't break anything, while fixing the current issue with some providers

Fixes #4186

Some database providers, like supabase, provides two URLs to access the database. A main URL behind pgBouncer's for load balancing, and a direct separated URL to perform migrations (running DDL operations), as does not support
advisory locks or multi-statement DDL required by migrations.

Before v3.1.0, adding `directUrl` along with `url` to `prisma/schema.prisma` was enought. Now, I'm making a commit to use direct url when set
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

@tairosonloa is attempting to deploy a commit to the Umami Software Team on Vercel.

A member of the Team first needs to authorize it.

@tairosonloa tairosonloa changed the title fix: fixes 4186 fix: fixes #4186 Apr 20, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 20, 2026

Greptile Summary

This PR fixes migration failures on providers (e.g. Supabase) that require a direct database URL for DDL operations by reading DIRECT_DATABASE_URL and overriding DATABASE_URL in the environment passed to prisma migrate deploy. The fallback to DATABASE_URL when the new variable is absent is correct, so existing deployments are unaffected.

Confidence Score: 5/5

Safe to merge — the change is minimal, targeted, and cannot break deployments that don't set DIRECT_DATABASE_URL.

Only one file changed, logic is straightforward, the fallback preserves existing behavior, and the sole finding is a P2 style suggestion about leaving DIRECT_DATABASE_URL in the child env.

No files require special attention.

Important Files Changed

Filename Overview
scripts/check-db.js Adds DIRECT_DATABASE_URL support for prisma migrate deploy by overriding DATABASE_URL in the child process env; logic is correct and the fallback to DATABASE_URL is safe.

Sequence Diagram

sequenceDiagram
    participant S as check-db.js
    participant E as process.env
    participant P as prisma migrate deploy

    S->>E: read DIRECT_DATABASE_URL
    alt DIRECT_DATABASE_URL is set
        E-->>S: directUrl = DIRECT_DATABASE_URL
    else not set / empty
        E-->>S: directUrl = DATABASE_URL
    end
    S->>P: execSync with env { ...process.env, DATABASE_URL: directUrl }
    P-->>S: migration output
Loading

Reviews (1): Last reviewed commit: "fix: fixes 4186" | Re-trigger Greptile

Comment thread scripts/check-db.js
if (!process.env.SKIP_DB_MIGRATION) {
console.log(execSync('prisma migrate deploy').toString());
const directUrl = process.env.DIRECT_DATABASE_URL || process.env.DATABASE_URL;
console.log(execSync('prisma migrate deploy', { env: { ...process.env, DATABASE_URL: directUrl } }).toString());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 DIRECT_DATABASE_URL still present in child env may confuse Prisma

When DIRECT_DATABASE_URL is set, this code overrides DATABASE_URL with the direct URL, but DIRECT_DATABASE_URL is still forwarded to the child process via ...process.env. If the prisma/schema.prisma still declares directUrl = env("DIRECT_DATABASE_URL"), Prisma will see both url and directUrl pointing at the same direct connection string, which is harmless but redundant. More importantly, if a future schema re-adds directUrl, the override here could silently become a no-op for some Prisma versions that prefer directUrl over url for migrations. Consider unsetting DIRECT_DATABASE_URL in the forwarded env to make the intent explicit:

Suggested change
console.log(execSync('prisma migrate deploy', { env: { ...process.env, DATABASE_URL: directUrl } }).toString());
console.log(execSync('prisma migrate deploy', { env: { ...process.env, DATABASE_URL: directUrl, DIRECT_DATABASE_URL: undefined } }).toString());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to 3.1. fails

1 participant