Using Entra ID for authenticating in drizzle.config.ts

Attempting to use best practices and use the service principal in our Azure to authenticate to postgres, however i cannot do awaits inside the drizzle.config.ts so i cannot retrieve the token when running drizzle-kit push

import { defineConfig, type Config } from 'drizzle-kit';
if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');

import { ClientSecretCredential, DefaultAzureCredential } from '@azure/identity';

const host = "elephant-dev.postgres.database.azure.com:5432/sagalabs";
const database = "sagalabs";
const port = 5432;
const ssl = true;

const credential = new DefaultAzureCredential();
var accessToken = await credential.getToken('https://ossrdbms-aad.database.windows.net/.default');


export default defineConfig({
  schema: './src/lib/schema.ts',
  dbCredentials: {
    host: host,
    database: database,
    port: port,
    user: `SagaLabs-Dev-staging`,
    password: accessToken.token,
    ssl: ssl ? { rejectUnauthorized: false } : false,
  },
  verbose: true,
  strict: true,
  dialect: 'postgresql'
}) satisfies Config;
Was this page helpful?