Browse Source

refactor: update database URL handling and temporary working directory logic

Enhance the environment configuration for the SQLite database by adjusting the handling of the DATABASE_URL to ensure correct file path resolution based on the NODE_ENV variable. Modify the temporary working directory logic to correctly set paths for both production and development environments, improving overall path management.
main
npmrun 11 hours ago
parent
commit
22a06b4209
  1. 2
      packages/drizzle-pkg/database/sqlite/db.ts
  2. BIN
      packages/drizzle-pkg/db.sqlite
  3. 14
      packages/drizzle-pkg/env.ts

2
packages/drizzle-pkg/database/sqlite/db.ts

@ -6,7 +6,7 @@ if (process.env.NODE_ENV === 'production') {
import('drizzle-orm/better-sqlite3/migrator')
}
const tempCwd = process.env.NODE_ENV === 'production'
const tempCwd = process.env.NODE_ENV !== 'production'
? path.resolve(process.cwd(), 'packages/drizzle-pkg')
: process.cwd();

BIN
packages/drizzle-pkg/db.sqlite

Binary file not shown.

14
packages/drizzle-pkg/env.ts

@ -1,4 +1,18 @@
import { config } from 'dotenv';
import path from 'path';
config({ path: '../../.env' });
const tempCwd = process.env.NODE_ENV === 'production'
? path.resolve(process.cwd(), 'packages/drizzle-pkg')
: process.cwd();
let dbUrl = process.env.DATABASE_URL;
if (dbUrl && dbUrl.startsWith('file:')) {
let filePath = dbUrl.slice(5);
if (!path.isAbsolute(filePath)) {
filePath = path.resolve(tempCwd, filePath);
process.env.DATABASE_URL = 'file:' + filePath;
}
}

Loading…
Cancel
Save