SPB Git
711 B · 9 lines typescript
1import postgres from "postgres";2/** Admin client for migrations/backups. Accepts libpq-style socket URLs such as `postgres://user@/db?host=/tmp` (Homebrew Postgres, trust over the unix socket). */3export function adminSql() {4  const url = process.env.DATABASE_URL_ADMIN ?? process.env.DATABASE_URL; if (!url) throw new Error("DATABASE_URL_ADMIN missing");5  const m = /^postgres(?:ql)?:\/\/([^@\/:]*)(?::[^@\/]*)?@\/([^?]+)\?host=(\/.+)$/.exec(url);6  if (m) return postgres({ path: m[3].endsWith(".s.PGSQL.5432") ? m[3] : `${m[3]}/.s.PGSQL.5432`, database: m[2], username: decodeURIComponent(m[1]) || process.env.USER, max: 1, onnotice: () => {} });7  return postgres(url, { max: 1, onnotice: () => {} });8}9
Files · ef2aafa50a0de3a6025a4230d5261ba6d89d122c
Menu

Theme