import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; import { defineConfig } from 'drizzle-kit'; // Same .env loading as officer_db's config: drizzle-kit runs as its own process from this directory and // inherits nothing from the server. const envPath = resolve(__dirname, '../../../.env'); try { const text = readFileSync(envPath, 'utf-8'); for (const line of text.split('\n')) { const match = line.match(/^(\w+)=(.*)$/); if (match) { const [, key, val] = match; if (!process.env[key!]) process.env[key!] = val!.replace(/^["']|["']$/g, ''); } } } catch {} // Derived exactly the way the runtime derives it — see src/db.ts. Duplicated rather than imported // because drizzle-kit loads this file outside the workspace's module resolution. const url = (() => { if (process.env.MARKETPLACE_POSTGRES_URL) return process.env.MARKETPLACE_POSTGRES_URL; const base = process.env.OFFICERDEV_POSTGRES_URL ?? process.env.POSTGRES_URL; if (!base) throw new Error('MARKETPLACE_POSTGRES_URL or POSTGRES_URL is required'); const parsed = new URL(base); parsed.pathname = '/officer_marketplace'; return parsed.toString(); })(); export default defineConfig({ schema: './src/schema.ts', out: './migrations', dialect: 'postgresql', dbCredentials: { url }, });