Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-db-env-var-loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/db': patch
---

Fixed `ASTRO_DATABASE_FILE` environment variable not being read from `.env` files during build. The `databaseFileEnvDefined()` function now uses `getAstroEnv()` which correctly loads `ASTRO_`-prefixed env vars, instead of Vite's `loadEnv()` which defaults to only loading `VITE_`-prefixed variables.
5 changes: 2 additions & 3 deletions packages/db/src/core/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import colors from 'piccolore';
import {
createServer,
type HotPayload,
loadEnv,
mergeConfig,
type RunnableDevEnvironment,
type UserConfig,
Expand All @@ -20,7 +19,7 @@ import { CONFIG_FILE_NAMES, DB_PATH, VIRTUAL_MODULE_ID } from '../consts.js';
import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from '../errors.js';
import { resolveDbConfig } from '../load-file.js';
import { SEED_DEV_FILE_NAME } from '../queries.js';
import { getDbDirectoryUrl, getRemoteDatabaseInfo, type VitePlugin } from '../utils.js';
import { getAstroEnv, getDbDirectoryUrl, getRemoteDatabaseInfo, type VitePlugin } from '../utils.js';
import { fileURLIntegration } from './file-url.js';
import { getDtsContent } from './typegen.js';
import {
Expand Down Expand Up @@ -209,7 +208,7 @@ function astroDBIntegration(options?: AstroDBConfig): AstroIntegration {
}

function databaseFileEnvDefined() {
const env = loadEnv('', process.cwd());
const env = getAstroEnv();
return env.ASTRO_DATABASE_FILE != null || process.env.ASTRO_DATABASE_FILE != null;
}

Expand Down