fix: fixes #4186#4192
Conversation
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
|
@tairosonloa is attempting to deploy a commit to the Umami Software Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes migration failures on providers (e.g. Supabase) that require a direct database URL for DDL operations by reading Confidence Score: 5/5Safe to merge — the change is minimal, targeted, and cannot break deployments that don't set Only one file changed, logic is straightforward, the fallback preserves existing behavior, and the sole finding is a P2 style suggestion about leaving No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
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
Reviews (1): Last reviewed commit: "fix: fixes 4186" | Re-trigger Greptile |
| 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()); |
There was a problem hiding this comment.
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:
| 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()); |
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
directUrlalong withurltoprisma/schema.prismawas enought.Now, I'm making a commit to use direct URL when set (env variable
DIRECT_DATABASE_URLexists and is not empty). Otherwise, default to the already existingDATABASE_URL. This should work for all deployments, so it shouldn't break anything, while fixing the current issue with some providersFixes #4186