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:
- Reverse-lookup: when a host is known but no resource path is,
scan projects -> branches -> endpoints for a matching
status.hosts.hostand recover the owning project/branch/endpoint. - 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. - Auto-create: when no projects exist at all, create one whose
id defaults to
project.name()slugified (override withconfig.autoCreate: "my-id"or disable withconfig.autoCreate: false). The create call is idempotent - anALREADY_EXISTSresponse from a concurrent boot is treated as success. Then poll the default endpoint until it reportscurrent_stateREADYorIDLE.
applyLakebaseToEnv writes the resolved values back to
process.env so the downstream lakebase plugin picks them up.
https://docs.databricks.com/api/workspace/postgres