Files
Eric Allam 01b8dcf03b feat(dashboard-agent-db): run migrations over a direct (non-pooler) connection (#4054)
## Summary

The in-dashboard agent's datastore now runs migrations over a direct
(non-pooler) connection. A transaction-mode pooler can't run the
migrator (no advisory locks, no multi-statement DDL), so when the
agent's database sits behind a pooler the migration step needs a
separate direct connection.

The application keeps connecting over the pooled
`DASHBOARD_AGENT_DATABASE_URL`. Only the migration entry points changed
(`drizzle.config.ts`, `migrate.mjs`, `migrate-status.mjs`); the runtime
client is untouched.

## Connection resolution (migrations)

```
DASHBOARD_AGENT_DIRECT_URL    direct agent connection (used for migrations)
DASHBOARD_AGENT_DATABASE_URL  pooled agent connection (preserves current behavior)
DIRECT_URL                    main direct connection (single-database fallback)
DATABASE_URL                  last resort
```

Mirrors the existing `DATABASE_URL` / `DIRECT_URL` split. Fully
backward-compatible: with nothing new set, resolution is identical to
before. The agent-specific vars take precedence over the main
`DIRECT_URL`, so a separate agent database is never migrated against the
wrong one. When the agent falls back to the main single database,
migrations now prefer its direct connection.
2026-06-26 11:09:36 +01:00

26 lines
1.1 KiB
TypeScript

import { defineConfig } from "drizzle-kit";
// Migrations need a direct (non-pooler) connection; a transaction-mode pooler
// can't run the migrator. Prefer the agent's direct url, then its pooled url,
// then the main DIRECT_URL/DATABASE_URL (OSS single-database fallback; tables
// still land in the trigger_dashboard_agent schema).
const url =
process.env.DASHBOARD_AGENT_DIRECT_URL ??
process.env.DASHBOARD_AGENT_DATABASE_URL ??
process.env.DIRECT_URL ??
process.env.DATABASE_URL ??
"postgres://placeholder"; // generate is offline; a real url is only needed for migrate/studio
export default defineConfig({
schema: "./src/schema.ts",
out: "./drizzle",
dialect: "postgresql",
// Only manage our schema — never introspect or diff Prisma's `public` schema.
schemaFilter: ["trigger_dashboard_agent"],
// Own journal table so dev (`drizzle-kit migrate`) and deploy (migrate.mjs)
// share one history and we don't cross-poison the default
// drizzle.__drizzle_migrations when the DB is shared. See migrate.mjs.
migrations: { table: "__dashboard_agent_migrations", schema: "drizzle" },
dbCredentials: { url },
});