problems with config file dialect for PostgreSQL

versions: drizzle-orm: 0.32.2 drizzle-kit: 0.23.2 I have something like this for my config file:
import 'dotenv/config';
import type { Config } from 'drizzle-kit';

const {
PGUSER,
PGPASSWORD,
PGHOST,
PGPORT,
PGDATABASE
} = process.env

export default {
schema: './src/lib/db/drizzle/schema.ts',
out: './src/lib/db/drizzle',
dialect: 'postgresql',
dbCredentials: {
user: String(PGUSER),
password: String(PGPASSWORD),
host: String(PGHOST),
port: Number(PGPORT),
database: String(PGDATABASE)
},
verbose: true,
strict: true
} satisfies Config
import 'dotenv/config';
import type { Config } from 'drizzle-kit';

const {
PGUSER,
PGPASSWORD,
PGHOST,
PGPORT,
PGDATABASE
} = process.env

export default {
schema: './src/lib/db/drizzle/schema.ts',
out: './src/lib/db/drizzle',
dialect: 'postgresql',
dbCredentials: {
user: String(PGUSER),
password: String(PGPASSWORD),
host: String(PGHOST),
port: Number(PGPORT),
database: String(PGDATABASE)
},
verbose: true,
strict: true
} satisfies Config
and when I try to use this config file, say for the introspect command of drizzle-kit, I get an error that says this:
No config path provided, using default 'drizzle.config.ts'
Reading config file '[path_to_project_root]\drizzle.config.ts'
Error Please provide required params:
[✓] dialect: 'postgresql'
No config path provided, using default 'drizzle.config.ts'
Reading config file '[path_to_project_root]\drizzle.config.ts'
Error Please provide required params:
[✓] dialect: 'postgresql'
which is clearly available in my config file. However, if I change the dbCredential to use a URL string with a template string to use my environment variables, it works just fine. So what's the issue here? side note I execute drizzle-kit using pnpm exec since I use pnpm on this project.
11 Replies
Francis A.
Francis A.4mo ago
Hello, Not sure its going to help... I had this error when i changed my .env file name to .env.local. Im not sure how you can fix the path, but i belive that the credentials are not beeing accessed. In my case i was just testing something related to authentication, so i went back to the original file name and it worked.
Darren
Darren4mo ago
you can't destructure process.env (in nextjs)*
Singodimejo
SingodimejoOP4mo ago
I’m using sveltekit You’d think so, but if I use the url key for the dbCredential and make the url string using template strings to leverage the environment variables it works just fine. I even made sure by putting a console log in the config file so whenever I run a command it would spit out the variables used and they all seem correct
Darren
Darren4mo ago
Out of interest what do you get if you write PGUSER as string and not String(PGUSER)
Singodimejo
SingodimejoOP4mo ago
Then the Config type shows me an error since PGUSER would be string | null
Darren
Darren4mo ago
Write PGUSER!
Singodimejo
SingodimejoOP4mo ago
I don’t have access to the code rn since it’s on my work laptop that I left in my office, but I don’t see how that would help since it’ll be a similar result to my current set up, no? I’d give it a try on monday and keep y’all updated. If y’all have any other ideas I can try, let me know!
Darren
Darren4mo ago
well last option is switch to
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
dbCredentials: {
host: "",
port: "",
user: "",
password: "",
database: "",
ssl: true, // can be boolean | "require" | "allow" | "prefer" | "verify-full" | options from node:tls
}
})
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
dbCredentials: {
host: "",
port: "",
user: "",
password: "",
database: "",
ssl: true, // can be boolean | "require" | "allow" | "prefer" | "verify-full" | options from node:tls
}
})
defineConfig not config
Singodimejo
SingodimejoOP4mo ago
cool, thanks for the advice, will give that a try later
Black Panther
Black Panther4mo ago
Still not fixed for me and getting same error "drizzle-orm": "^0.33.0", "drizzle-kit": "^0.24.0", import { defineConfig } from 'drizzle-kit'; export default defineConfig({ schema: './src/db/schema/*', out: './drizzle', verbose: true, strict: true, introspect: { casing: 'preserve', }, dialect: 'postgresql', dbCredentials: { user: 'postgres', password: 'root', host: '127.0.0.1', port: 5432, database: 'property', }, }); My schemas folder is empty but even changing it to schema.ts (which is an empty file) doesn't fix the error
Darren
Darren4mo ago
can you post teh error
Want results from more Discord servers?
Add your server