From 5931cf28fb5515afcb32ec0630e6d8e9dfb9feef Mon Sep 17 00:00:00 2001 From: serfa Date: Sun, 23 Aug 2026 13:33:06 -0400 Subject: [PATCH] assets:migrate must not require a .env file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It read the repo-root .env with a bare readFileSync and died on ENOENT where there wasn't one — which is every container, including the server this deploys to. Migrations and the seed both ran fine on the Dokploy host; this was the only step of the deployment that could not. The loop already used `??=`, so a variable present in the environment always won and the file was never the authority. Its absence is now the ordinary case it always should have been. Co-Authored-By: Claude Opus 5 (1M context) --- packages/db/src/migrate-assets.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/db/src/migrate-assets.ts b/packages/db/src/migrate-assets.ts index 1caaeb5..8ae566e 100644 --- a/packages/db/src/migrate-assets.ts +++ b/packages/db/src/migrate-assets.ts @@ -26,9 +26,21 @@ import { import * as schema from './schema/index'; import { readSsl } from './client'; -for (const line of readFileSync(new URL('../../../.env', import.meta.url), 'utf8').split('\n')) { - const m = /^([A-Z_]+)=(.*)$/.exec(line.trim()); - if (m?.[1]) process.env[m[1]] ??= m[2]; +/* + * The repo-root .env, when there is one. + * + * `??=` means a variable already in the environment always wins, which is what + * makes this safe to skip: in a container there is no .env and the platform + * supplies everything directly. Insisting on the file turned this script into + * the one step of a deployment that could not run on the server it deploys to. + */ +try { + for (const line of readFileSync(new URL('../../../.env', import.meta.url), 'utf8').split('\n')) { + const m = /^([A-Z_]+)=(.*)$/.exec(line.trim()); + if (m?.[1]) process.env[m[1]] ??= m[2]; + } +} catch { + // No .env — expected anywhere the environment is injected rather than filed. } const url = process.env.DATABASE_URL;