Skip to content

lakebaseResolver

Lakebase Postgres connection resolver.

Reads the same env vars the lakebase plugin consumes (PGHOST, PGDATABASE, PGPORT, PGSSLMODE, LAKEBASE_ENDPOINT) and fills in whichever pieces are missing using the Lakebase Autoscaling REST API under /api/2.0/postgres/ via the Databricks workspace client.

LAKEBASE_ENDPOINT (and config.endpoint) accept anything parseAddress understands - canonical resource paths, Postgres URIs, bare hostnames, or bare project ids. The resolver layers whatever pieces fall out of parsing under explicit config / env values, then fills the remaining gaps via the API:

  1. Reverse-lookup: when a host is known but no resource path is, scan projects -> branches -> endpoints for a matching status.hosts.host and recover the owning project/branch/endpoint.
  2. Pick: when a project is known but child resources aren’t, prefer the server-side default (status.default, ENDPOINT_TYPE_READ_WRITE, databricks_postgres) and fall back to “the only one” when a listing returns a single result.
  3. Auto-create: when no projects exist at all, create one whose id defaults to project.name() slugified (override with config.autoCreate: "my-id" or disable with config.autoCreate: false). The create call is idempotent - an ALREADY_EXISTS response from a concurrent boot is treated as success. Then poll the default endpoint until it reports current_state READY or IDLE.

applyLakebaseToEnv writes the resolved values back to process.env so the downstream lakebase plugin picks them up.

https://docs.databricks.com/api/workspace/postgres