diff --git a/.changeset/lemon-beans-admire.md b/.changeset/lemon-beans-admire.md new file mode 100644 index 000000000000..d593bd74340f --- /dev/null +++ b/.changeset/lemon-beans-admire.md @@ -0,0 +1,5 @@ +--- +'@astrojs/db': patch +--- + +Fixes a bug where `astro:db:seed` couldn't access to the environment variable `ASTRO_DATABASE_FILE` diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index 29e98222ea87..7e10699df70a 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -124,12 +124,13 @@ export function getLocalVirtualModContents({ tables: DBTables; root: URL; }) { + const { ASTRO_DATABASE_FILE } = getAstroEnv(); const dbInfo = getRemoteDatabaseInfo(); const dbUrl = new URL(DB_PATH, root); return ` import { asDrizzleTable, createLocalDatabaseClient, normalizeDatabaseUrl } from ${RUNTIME_IMPORT}; -const dbUrl = normalizeDatabaseUrl(import.meta.env.ASTRO_DATABASE_FILE, ${JSON.stringify(dbUrl)}); +const dbUrl = normalizeDatabaseUrl(${JSON.stringify(ASTRO_DATABASE_FILE)}, ${JSON.stringify(dbUrl)}); export const db = createLocalDatabaseClient({ dbUrl, enableTransactions: ${dbInfo.url === 'libsql'} }); export * from ${RUNTIME_VIRTUAL_IMPORT};