Setting connectionString from env in sveltekit

I've been trying to get my connection string from .env into the drizzle.config.ts file, but vite aliases are not working within the file, so i cannot access the aliased sveltekit env variables. I really don't want to export the variable as VITE_ since that could be a security risk in the future.
4 Replies
mrgentlehashtag3542
mrgentlehashtag3542OP15mo ago
No worries, resolved it with dotenv
import { Config } from "drizzle-kit";
import * as dotenv from 'dotenv';
dotenv.config();

export default {
schema: [
'./src/schema/task.ts'
],
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: process.env.DRIZZLE_DATABASE_URL!
}
} satisfies Config;
import { Config } from "drizzle-kit";
import * as dotenv from 'dotenv';
dotenv.config();

export default {
schema: [
'./src/schema/task.ts'
],
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: process.env.DRIZZLE_DATABASE_URL!
}
} satisfies Config;
Budi
Budi12mo ago
That worked for me too, however I don't understand why the SvelteKit $env pariables aren't accessible in this file. Did you learn why?
Angelelz
Angelelz12mo ago
Please remember that drizzle-kit is a CLI tool that is working outside SvelteKit As such it doesn't have access to the environment variables that SvelteKit makes available to its own runtime So you have to make it available somehow, for example with dotenv
Budi
Budi12mo ago
I see. That's helpful, thanks @Angelelz.
Want results from more Discord servers?
Add your server