Drizzle-kit database push connection error

When trying to run drizzle-kit push:mysql to push my schema to Planetscale, I get the following error. Am I missing something?
drizzle-kit push:mysql
drizzle-kit: v0.19.3
drizzle-orm: v0.27.0

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/drizzle.config.ts'
/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:34877
const createConnectionErr = new Error();
^

Error: getaddrinfo ENOTFOUND ${DATABASE_HOST}
at createConnection2 (/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:34877:35)
at connectToMySQL (/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:36958:60)
at Command.<anonymous> (/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:52048:28) {
code: 'ENOTFOUND',
errno: -3008,
sqlState: undefined
}

Node.js v20.2.0
drizzle-kit push:mysql
drizzle-kit: v0.19.3
drizzle-orm: v0.27.0

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/drizzle.config.ts'
/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:34877
const createConnectionErr = new Error();
^

Error: getaddrinfo ENOTFOUND ${DATABASE_HOST}
at createConnection2 (/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:34877:35)
at connectToMySQL (/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:36958:60)
at Command.<anonymous> (/Users/gerbuuun/ghq/github.com/Gerbuuun/my-admin-nuxt/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:52048:28) {
code: 'ENOTFOUND',
errno: -3008,
sqlState: undefined
}

Node.js v20.2.0
This is my drizzle.config.ts
import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
dotenv.config();

export default {
schema: "./database/schema/*",
out: "./drizzle",
driver: "mysql2",
dbCredentials: {
connectionString: process.env.DATABASE_URL as string,
},
} satisfies Config;
import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
dotenv.config();

export default {
schema: "./database/schema/*",
out: "./drizzle",
driver: "mysql2",
dbCredentials: {
connectionString: process.env.DATABASE_URL as string,
},
} satisfies Config;
And my .env file looks like this:
# Database
DATABASE_HOST=aws.connect.psdb.cloud
DATABASE_USERNAME=<hidden>
DATABASE_PASSWORD=<hidden>
DATABASE_NAME=<hidden>
DATABASE_URL=mysql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?ssl={"rejectUnauthorized":true}
# Database
DATABASE_HOST=aws.connect.psdb.cloud
DATABASE_USERNAME=<hidden>
DATABASE_PASSWORD=<hidden>
DATABASE_NAME=<hidden>
DATABASE_URL=mysql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?ssl={"rejectUnauthorized":true}
3 Replies
McPizza
McPizza2y ago
AFAIK the standard dotenv does not support dynamic values Does it work if you just set the string manually instead of dynamically? You may also need to wrap the whole env in ' ' to ensure characters are escaped correctly
Gerbuuun
GerbuuunOP2y ago
Aha, gotcha. That solved the problem. Thanks!
McPizza
McPizza2y ago
You could also have it be dynamic:
dbCredentials: {
connectionString: `mysql://${process.env.DATABASE_USERNAME}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}/${process.env.DATABASE_NAME}?ssl={"rejectUnauthorized":true}`,
},
dbCredentials: {
connectionString: `mysql://${process.env.DATABASE_USERNAME}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}/${process.env.DATABASE_NAME}?ssl={"rejectUnauthorized":true}`,
},
Want results from more Discord servers?
Add your server