From 0425173df09f2115d4ee6901e8a7222e8aaf2774 Mon Sep 17 00:00:00 2001 From: liudmylasovetovs Date: Sat, 28 Mar 2026 00:13:03 -0700 Subject: [PATCH 1/2] (SP: 1) [FIX] Hot fix index APP ENV --- frontend/db/index.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/db/index.ts b/frontend/db/index.ts index f58ea350..22fda6c4 100644 --- a/frontend/db/index.ts +++ b/frontend/db/index.ts @@ -11,26 +11,30 @@ dotenv.config(); type AppDatabase = PgDatabase; -const APP_ENV = process.env.APP_ENV ?? 'local'; +const APP_ENV = process.env.APP_ENV?.trim(); +const IS_LOCAL_ENV = APP_ENV === 'local'; const STRICT_LOCAL_DB_GUARD = process.env.SHOP_STRICT_LOCAL_DB === '1'; const REQUIRED_LOCAL_DB_URL = process.env.SHOP_REQUIRED_DATABASE_URL_LOCAL; if (STRICT_LOCAL_DB_GUARD) { - if (APP_ENV !== 'local') { + if (!IS_LOCAL_ENV) { throw new Error( - `[db] SHOP_STRICT_LOCAL_DB=1 requires APP_ENV=local (got "${APP_ENV}")` + `[db] SHOP_STRICT_LOCAL_DB=1 requires APP_ENV=local (got "${APP_ENV ?? 'undefined'}")` ); } + if (!process.env.DATABASE_URL_LOCAL?.trim()) { throw new Error( '[db] SHOP_STRICT_LOCAL_DB=1 requires DATABASE_URL_LOCAL to be set' ); } + if (process.env.DATABASE_URL?.trim()) { throw new Error( '[db] SHOP_STRICT_LOCAL_DB=1 forbids DATABASE_URL during shop-local tests' ); } + if ( REQUIRED_LOCAL_DB_URL && process.env.DATABASE_URL_LOCAL !== REQUIRED_LOCAL_DB_URL @@ -43,8 +47,8 @@ if (STRICT_LOCAL_DB_GUARD) { let db: AppDatabase; -if (APP_ENV === 'local') { - const url = process.env.DATABASE_URL_LOCAL; +if (IS_LOCAL_ENV) { + const url = process.env.DATABASE_URL_LOCAL?.trim(); if (!url) { throw new Error('[db] APP_ENV=local requires DATABASE_URL_LOCAL to be set'); @@ -60,10 +64,12 @@ if (APP_ENV === 'local') { console.log('[db] using local PostgreSQL (pg)'); } } else { - const url = process.env.DATABASE_URL; + const url = process.env.DATABASE_URL?.trim(); if (!url) { - throw new Error(`[db] APP_ENV=${APP_ENV} requires DATABASE_URL to be set`); + throw new Error( + `[db] APP_ENV=${APP_ENV ?? 'undefined'} requires DATABASE_URL to be set` + ); } const sql = neon(url); From 3f1906e8d71f2a30fbee2fb69130ea31158a5cc0 Mon Sep 17 00:00:00 2001 From: liudmylasovetovs Date: Sat, 28 Mar 2026 00:22:24 -0700 Subject: [PATCH 2/2] (SP: 1) [FIX] normalize APP ENV before local runtime check --- frontend/db/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/db/index.ts b/frontend/db/index.ts index 22fda6c4..8648dd00 100644 --- a/frontend/db/index.ts +++ b/frontend/db/index.ts @@ -11,7 +11,7 @@ dotenv.config(); type AppDatabase = PgDatabase; -const APP_ENV = process.env.APP_ENV?.trim(); +const APP_ENV = process.env.APP_ENV?.trim().toLowerCase(); const IS_LOCAL_ENV = APP_ENV === 'local'; const STRICT_LOCAL_DB_GUARD = process.env.SHOP_STRICT_LOCAL_DB === '1'; const REQUIRED_LOCAL_DB_URL = process.env.SHOP_REQUIRED_DATABASE_URL_LOCAL;