Skip to content

Commit d422879

Browse files
committed
feat(appkit): support Lakebase Autoscaling x Apps integration natively
1 parent 9fc9700 commit d422879

9 files changed

Lines changed: 95 additions & 42 deletions

File tree

docs/docs/plugins/lakebase.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Provides a PostgreSQL connection pool for Databricks Lakebase Autoscaling with a
1111
- Automatic OAuth token refresh (1-hour tokens, 2-minute refresh buffer)
1212
- Token caching to minimize API calls
1313
- Built-in OpenTelemetry instrumentation (query duration, pool connections, token refresh)
14+
- AppKit logger configured by default for query and connection events
1415

1516
## Setting up Lakebase
1617

@@ -108,23 +109,26 @@ The required environment variables:
108109

109110
| Variable | Description |
110111
|---|---|
111-
| `PGHOST` | Lakebase host |
112-
| `PGDATABASE` | Database name |
113112
| `LAKEBASE_ENDPOINT` | Endpoint resource path (e.g. `projects/.../branches/.../endpoints/...`) |
114-
| `PGSSLMODE` | TLS mode — set to `require` |
113+
| `PGHOST` | Lakebase host (auto-injected in production by the `postgres` Databricks Apps resource) |
114+
| `PGDATABASE` | Database name (auto-injected in production by the `postgres` Databricks Apps resource) |
115+
| `PGSSLMODE` | TLS mode — set to `require` (auto-injected in production by the `postgres` Databricks Apps resource) |
115116

116-
Ensure that those environment variables are set both for local development (`.env` file) and for deployment (`app.yaml` file):
117+
When deployed to Databricks Apps with a `postgres` database resource configured, `PGHOST`, `PGDATABASE`, `PGSSLMODE`, `PGUSER`, `PGPORT`, and `PGAPPNAME` are automatically injected by the platform. Only `LAKEBASE_ENDPOINT` must be set explicitly:
117118

118119
```yaml
119120
env:
120121
- name: LAKEBASE_ENDPOINT
121-
value: projects/{project-id}/branches/{branch-id}/endpoints/primary
122-
- name: PGHOST
123-
value: {your-lakebase-host}
124-
- name: PGDATABASE
125-
value: databricks_postgres
126-
- name: PGSSLMODE
127-
value: require
122+
valueFrom: postgres
123+
```
124+
125+
For local development, set all variables in your `.env` file:
126+
127+
```env
128+
PGHOST=your-lakebase-host.databricks.com
129+
PGDATABASE=databricks_postgres
130+
LAKEBASE_ENDPOINT=projects/<project-id>/branches/<branch-id>/endpoints/<endpoint-id>
131+
PGSSLMODE=require
128132
```
129133

130134
For the full configuration reference (SSL, pool size, timeouts, logging, ORM examples), see the [`@databricks/lakebase` README](https://github.com/databricks/appkit/blob/main/packages/lakebase/README.md).

docs/static/schemas/plugin-manifest.schema.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"uc_function",
103103
"uc_connection",
104104
"database",
105+
"postgres",
105106
"genie_space",
106107
"experiment",
107108
"app"
@@ -153,6 +154,11 @@
153154
"enum": ["CAN_CONNECT_AND_CREATE"],
154155
"description": "Permission for database resources"
155156
},
157+
"postgresPermission": {
158+
"type": "string",
159+
"enum": ["CAN_CONNECT_AND_CREATE"],
160+
"description": "Permission for Postgres resources"
161+
},
156162
"genieSpacePermission": {
157163
"type": "string",
158164
"enum": ["CAN_VIEW", "CAN_RUN", "CAN_EDIT", "CAN_MANAGE"],
@@ -328,6 +334,17 @@
328334
}
329335
}
330336
},
337+
{
338+
"if": {
339+
"properties": { "type": { "const": "postgres" } },
340+
"required": ["type"]
341+
},
342+
"then": {
343+
"properties": {
344+
"permission": { "$ref": "#/$defs/postgresPermission" }
345+
}
346+
}
347+
},
331348
{
332349
"if": {
333350
"properties": { "type": { "const": "genie_space" } },

packages/appkit/src/plugins/lakebase/manifest.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44
"displayName": "Lakebase",
55
"description": "SQL query execution against Databricks Lakebase Autoscaling",
66
"resources": {
7-
"required": [],
7+
"required": [
8+
{
9+
"type": "postgres",
10+
"alias": "Postgres",
11+
"resourceKey": "postgres",
12+
"description": "Lakebase Postgres database for persistent storage",
13+
"permission": "CAN_CONNECT_AND_CREATE",
14+
"fields": {
15+
"name": {
16+
"env": "LAKEBASE_ENDPOINT",
17+
"description": "Lakebase endpoint resource path"
18+
}
19+
}
20+
}
21+
],
822
"optional": []
923
}
1024
}

packages/appkit/src/registry/types.generated.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum ResourceType {
1212
UC_FUNCTION = "uc_function",
1313
UC_CONNECTION = "uc_connection",
1414
DATABASE = "database",
15+
POSTGRES = "postgres",
1516
GENIE_SPACE = "genie_space",
1617
EXPERIMENT = "experiment",
1718
APP = "app",
@@ -47,6 +48,9 @@ export type UcConnectionPermission = "USE_CONNECTION";
4748
/** Permissions for DATABASE resources */
4849
export type DatabasePermission = "CAN_CONNECT_AND_CREATE";
4950

51+
/** Permissions for POSTGRES resources */
52+
export type PostgresPermission = "CAN_CONNECT_AND_CREATE";
53+
5054
/** Permissions for GENIE_SPACE resources */
5155
export type GenieSpacePermission =
5256
| "CAN_VIEW"
@@ -71,6 +75,7 @@ export type ResourcePermission =
7175
| UcFunctionPermission
7276
| UcConnectionPermission
7377
| DatabasePermission
78+
| PostgresPermission
7479
| GenieSpacePermission
7580
| ExperimentPermission
7681
| AppPermission;
@@ -89,6 +94,7 @@ export const PERMISSION_HIERARCHY_BY_TYPE: Record<
8994
[ResourceType.UC_FUNCTION]: ["EXECUTE"],
9095
[ResourceType.UC_CONNECTION]: ["USE_CONNECTION"],
9196
[ResourceType.DATABASE]: ["CAN_CONNECT_AND_CREATE"],
97+
[ResourceType.POSTGRES]: ["CAN_CONNECT_AND_CREATE"],
9298
[ResourceType.GENIE_SPACE]: ["CAN_VIEW", "CAN_RUN", "CAN_EDIT", "CAN_MANAGE"],
9399
[ResourceType.EXPERIMENT]: ["CAN_READ", "CAN_EDIT", "CAN_MANAGE"],
94100
[ResourceType.APP]: ["CAN_USE"],

packages/lakebase/README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,11 @@ The driver calls `trace.getTracer('@databricks/lakebase')` and `metrics.getMeter
283283

284284
## AppKit Integration
285285

286-
This driver is also available as part of [@databricks/appkit](https://www.npmjs.com/package/@databricks/appkit):
286+
This driver is also available as part of [@databricks/appkit](https://www.npmjs.com/package/@databricks/appkit).
287287

288-
```typescript
289-
import { createLakebasePool } from "@databricks/appkit";
290-
291-
const pool = createLakebasePool();
292-
```
293-
294-
**Differences between standalone and AppKit:**
288+
While you can use the standalone driver, it is recommended to use the AppKit plugin for a more complete experience.
295289

296-
- **Standalone** (`@databricks/lakebase`): Silent by default - no logger configured
297-
- **AppKit** (`@databricks/appkit`): Automatically injects AppKit's logger with scope `appkit:connectors:lakebase`.
290+
Read the [AppKit documentation](https://databricks.github.io/appkit/docs/plugins/lakebase) for more information.
298291

299292
## Learn more about Lakebase Autoscaling
300293

packages/shared/src/schemas/plugin-manifest.schema.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"uc_function",
103103
"uc_connection",
104104
"database",
105+
"postgres",
105106
"genie_space",
106107
"experiment",
107108
"app"
@@ -153,6 +154,11 @@
153154
"enum": ["CAN_CONNECT_AND_CREATE"],
154155
"description": "Permission for database resources"
155156
},
157+
"postgresPermission": {
158+
"type": "string",
159+
"enum": ["CAN_CONNECT_AND_CREATE"],
160+
"description": "Permission for Postgres resources"
161+
},
156162
"genieSpacePermission": {
157163
"type": "string",
158164
"enum": ["CAN_VIEW", "CAN_RUN", "CAN_EDIT", "CAN_MANAGE"],
@@ -328,6 +334,17 @@
328334
}
329335
}
330336
},
337+
{
338+
"if": {
339+
"properties": { "type": { "const": "postgres" } },
340+
"required": ["type"]
341+
},
342+
"then": {
343+
"properties": {
344+
"permission": { "$ref": "#/$defs/postgresPermission" }
345+
}
346+
}
347+
},
331348
{
332349
"if": {
333350
"properties": { "type": { "const": "genie_space" } },

template/.env.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ DATABRICKS_HOST={{.workspaceHost}}
77
{{.dotEnv.content}}
88
{{- end}}
99
{{- if .plugins.lakebase}}
10-
PGHOST='' # Copy from the Lakebase Postgres UI
11-
PGDATABASE='databricks_postgres' # Copy from the Lakebase Postgres UI
12-
LAKEBASE_ENDPOINT='' # Run: databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}
13-
# PGUSER='' # optional, defaults to DATABRICKS_CLIENT_ID
10+
PGHOST=
11+
PGDATABASE=
12+
# Run: databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}
13+
LAKEBASE_ENDPOINT=
14+
# PGUSER= # optional, defaults to DATABRICKS_CLIENT_ID
1415
PGSSLMODE=require
1516
{{- end}}
1617
DATABRICKS_APP_PORT=8000

template/app.yaml.tmpl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
command: ['npm', 'run', 'start']
2+
{{- if .appEnv}}
23
env:
3-
{{- if .plugins.analytics}}
4-
- name: DATABRICKS_WAREHOUSE_ID
5-
valueFrom: sql-warehouse
4+
{{.appEnv}}
65
{{- end}}
7-
{{- if .plugins.lakebase}}
8-
- name: PGHOST
9-
value: "" # Copy from the Lakebase Postgres UI
10-
- name: PGDATABASE
11-
value: "databricks_postgres" # Copy from the Lakebase Postgres UI
12-
- name: LAKEBASE_ENDPOINT
13-
value: "" # Run: databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}
14-
- name: PGSSLMODE
15-
value: "require"
16-
# - name: PGUSER
17-
# value: "" # optional, defaults to DATABRICKS_CLIENT_ID
18-
{{- end}}

template/appkit.plugins.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@
3232
"description": "SQL query execution against Databricks Lakebase Autoscaling",
3333
"package": "@databricks/appkit",
3434
"resources": {
35-
"required": [],
35+
"required": [
36+
{
37+
"type": "postgres",
38+
"alias": "Postgres",
39+
"resourceKey": "postgres",
40+
"description": "Lakebase Postgres database for persistent storage",
41+
"permission": "CAN_CONNECT_AND_CREATE",
42+
"fields": {
43+
"name": {
44+
"env": "LAKEBASE_ENDPOINT",
45+
"description": "Lakebase endpoint resource path"
46+
}
47+
}
48+
}
49+
],
3650
"optional": []
3751
}
3852
},

0 commit comments

Comments
 (0)