-
-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE]: Support Top-level await in drizzle.config.ts
#1982
Comments
I am facing the same issue. I want to fetch db credentials from Azure Key Vault (same as AWS Secret Manager) and cannot do that... 🥲 |
I tried to wrap a promise around it but couldn't get it to work either. Any thoughts?
|
I am also having this issue. I am attempting to pull secrets from AWS Secrets manager in my JavaScript and I need top-level await to do that with Drizzle Kit's configuration file. I will have to abandon this strategy and instead use the AWS SDK for Linux to pull and set the environment variables at the OS level. Would be nice for top-level wait to be supported. |
Workaround:
But naturally would be great to just use top-level await. |
@paolostyle wouldn't the last line of your code snippet need export default await getConfig(); Since |
No, it doesn't. You don't ever have to await an async function, even though you probably should in most cases, but this is a config file processed by external code (drizzle-kit in this case). Considering it works, it likely awaits whatever is exported by the config file. I can't check it because a) That snippet isn't something I would use in my regular code but as I said, it's a workaround. |
Async config works for
Current (terrible) workaround: // drizzle.credentials.ts
import { CONNECTION_STRING } from './some-file-with-top-level-await.js';
console.log(CONNECTION_STRING); // drizzle.config.ts
import { execSync } from 'node:child_process';
import { createRequire } from 'node:module';
import type { Config } from 'drizzle-kit';
const require = createRequire(import.meta.url);
const CONNECTION_STRING = execSync(
`tsx --no-warnings ${require.resolve('./drizzle.credentials.ts')}`,
{ encoding: 'utf8' },
).trim();
export default {
dbCredentials: { url: CONNECTION_STRING },
// ...
} satisfies Config; |
I'm having the same issue as well, this seems like a very common use case, storing secrets in .env files is hard to share and keep out of version control than just using a better approach like using a secrets manager. Another workaround which doesn't require a code change is to run the migration while setting the env variable in the same command: Mac Terminal command:
|
Can't wait for this feature... It seems totally essential for any secrets manager. |
As an alternative way of requesting secrets from the vault. // drizzle.secrets.ts
import { getSecrets } from './get-secrets.ts'
const secrets = await getSecrets()
console.log(JSON.stringify(secrets)) // drizzle.config.ts
import { defineConfig } from 'drizzle-kit'
Object.assign(process.env, JSON.parse(process.env.SECRETS))
export default defineConfig({
schema: "./src/db/schema.ts",
out: "./src/db/migrations",
driver: "pg",
dbCredentials: {
url: process.env.DATABASE_URL,
},
}) package.json "db:migrate": "SECRETS=$(tsx --no-warnings './drizzle.secrets.ts') drizzle-kit migrate --config=drizzle.config.ts" |
looks like not drizzle issue |
defineConfig now accepts a promise for a config or function that returns one - fixes drizzle-team#1982
defineConfig now accepts a promise for a config or function that returns one - fixes drizzle-team#1982
Describe what you want
I want to write a configuration as follows. Here, fetchDatabaseUri is a function that retrieves authentication information from AWS Secrets Manager and returns the database URI.
drizzle.config.tableau.ts
Currently, when I run introspect with these settings, I get the following error:
The text was updated successfully, but these errors were encountered: