Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions docs/docs/plugins/lakebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,34 @@ Click the **Connect** button on your Lakebase branch and copy the `PGHOST` and `

### 5. Grant access to the service principal

Navigate to the **SQL Editor** tab on your Lakebase branch. Run the following SQL against the `databricks_postgres` database, replacing `<DATABRICKS_CLIENT_ID>` with the value from step 1 everywhere it appears:
Navigate to the **SQL Editor** tab on your Lakebase branch. Run the following SQL against the `databricks_postgres` database, replacing the service principal ID in the `DECLARE` block with the `DATABRICKS_CLIENT_ID` value from step 1:

```sql
-- 1. Create the extension and role
CREATE EXTENSION IF NOT EXISTS databricks_auth;
SELECT databricks_create_role('<DATABRICKS_CLIENT_ID>', 'SERVICE_PRINCIPAL');

-- 2. Basic connection & usage
GRANT CONNECT ON DATABASE "databricks_postgres" TO "<DATABRICKS_CLIENT_ID>";
GRANT ALL ON SCHEMA public TO "<DATABRICKS_CLIENT_ID>";

-- 3. Grant on existing objects
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "<DATABRICKS_CLIENT_ID>";
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO "<DATABRICKS_CLIENT_ID>";
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO "<DATABRICKS_CLIENT_ID>";
GRANT ALL PRIVILEGES ON ALL PROCEDURES IN SCHEMA public TO "<DATABRICKS_CLIENT_ID>";

-- 4. Grant on future objects
-- NOTE: This applies to objects created by the user running this script.
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON TABLES TO "<DATABRICKS_CLIENT_ID>";
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON SEQUENCES TO "<DATABRICKS_CLIENT_ID>";
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON FUNCTIONS TO "<DATABRICKS_CLIENT_ID>";
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON ROUTINES TO "<DATABRICKS_CLIENT_ID>";

DO $$
DECLARE
sp TEXT := 'your-service-principal-id'; -- Replace with DATABRICKS_CLIENT_ID from Step 1
BEGIN
-- Create service principal role
PERFORM databricks_create_role(sp, 'SERVICE_PRINCIPAL');

-- Connection and schema access
EXECUTE format('GRANT CONNECT ON DATABASE "databricks_postgres" TO %I', sp);
EXECUTE format('GRANT ALL ON SCHEMA public TO %I', sp);

-- Privileges on existing objects
EXECUTE format('GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO %I', sp);
EXECUTE format('GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO %I', sp);
EXECUTE format('GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO %I', sp);
EXECUTE format('GRANT ALL PRIVILEGES ON ALL PROCEDURES IN SCHEMA public TO %I', sp);

-- Default privileges on future objects you create
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO %I', sp);
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO %I', sp);
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO %I', sp);
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON ROUTINES TO %I', sp);
END $$;
```

![SQL Editor](./assets/lakebase-setup/step-5.png)
Expand Down
2 changes: 1 addition & 1 deletion packages/appkit/src/plugins/lakebase/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "Lakebase",
"description": "SQL query execution against Databricks Lakebase Autoscaling",
"onSetupMessage": "Configure environment variables before running or deploying the app.\nSee: https://databricks.github.io/appkit/docs/plugins/lakebase",
"hidden": true,
"hidden": false,
"resources": {
"required": [],
"optional": []
Expand Down
14 changes: 11 additions & 3 deletions template/.env.example.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
DATABRICKS_HOST=https://...
{{- if .dotenv_example}}
{{.dotenv_example}}
{{- if .dotEnv.example}}
{{.dotEnv.example}}
{{- end}}
{{- if .plugins.lakebase}}
PGHOST=your-lakebase-host.databricks.com
PGDATABASE=databricks_postgres
# Run: databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}
LAKEBASE_ENDPOINT=projects/<project-id>/branches/<branch-id>/endpoints/<endpoint-id>
# PGUSER=your_user # optional, defaults to DATABRICKS_CLIENT_ID
PGSSLMODE=require
{{- end}}
DATABRICKS_APP_PORT=8000
DATABRICKS_APP_NAME={{.project_name}}
DATABRICKS_APP_NAME={{.projectName}}
FLASK_RUN_HOST=0.0.0.0
19 changes: 15 additions & 4 deletions template/.env.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{{if ne .profile ""}}DATABRICKS_CONFIG_PROFILE={{.profile}}{{else}}DATABRICKS_HOST={{.workspace_host}}{{end}}
{{- if .dotenv}}
{{.dotenv}}
{{- if ne .profile ""}}
DATABRICKS_CONFIG_PROFILE={{.profile}}
{{- else}}
DATABRICKS_HOST={{.workspaceHost}}
{{- end}}
{{- if .dotEnv.content}}
{{.dotEnv.content}}
{{- end}}
{{- if .plugins.lakebase}}
PGHOST='' # Copy from the Lakebase Postgres UI
PGDATABASE='databricks_postgres' # Copy from the Lakebase Postgres UI
LAKEBASE_ENDPOINT='' # Run: databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}
# PGUSER='' # optional, defaults to DATABRICKS_CLIENT_ID
PGSSLMODE=require
{{- end}}
DATABRICKS_APP_PORT=8000
DATABRICKS_APP_NAME={{.project_name}}
DATABRICKS_APP_NAME={{.projectName}}
FLASK_RUN_HOST=0.0.0.0
26 changes: 15 additions & 11 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Minimal Databricks App

A minimal Databricks App powered by Databricks AppKit, featuring React, TypeScript, tRPC, and Tailwind CSS.
A minimal Databricks App powered by Databricks AppKit, featuring React, TypeScript, and Tailwind CSS.

## Prerequisites

- Node.js 18+ and npm
- Node.js v22+ and npm
- Databricks CLI (for deployment)
- Access to a Databricks workspace

Expand All @@ -18,12 +18,12 @@ For local development, configure your environment variables by creating a `.env`
cp env.example .env
```

Edit `.env` and set the following:
Edit `.env` and set the environment variables you need:

```env
DATABRICKS_HOST=https://your-workspace.cloud.databricks.com
DATABRICKS_WAREHOUSE_ID=your-warehouse-id
DATABRICKS_APP_PORT=8000
# ... other environment variables, depending on the plugins you use
```

### CLI Authentication
Expand Down Expand Up @@ -103,6 +103,8 @@ npm start

## Code Quality

There are a few commands to help you with code quality:

```bash
# Type checking
npm run typecheck
Expand Down Expand Up @@ -166,18 +168,20 @@ databricks bundle deploy -t prod

```
* client/ # React frontend
* src/ # Source code
* public/ # Static assets
* src/ # Source code
* public/ # Static assets
* server/ # Express backend
* server.ts # Server entry point
* trpc.ts # tRPC router
* server.ts # Server entry point
* routes/ # Routes
* shared/ # Shared types
* databricks.yml # Bundle configuration
* app.yaml # App configuration
* .env.example # Environment variables example
```

## Tech Stack

- **Frontend**: React 19, TypeScript, Vite, Tailwind CSS
- **Backend**: Node.js, Express, tRPC
- **Backend**: Node.js, Express
- **Frontend**: React.js, TypeScript, Vite, Tailwind CSS, React Router
- **UI Components**: Radix UI, shadcn/ui
- **Databricks**: App Kit SDK, Analytics SDK
- **Databricks**: AppKit SDK
16 changes: 14 additions & 2 deletions template/app.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
command: ['npm', 'run', 'start']
{{- if .app_env}}
env:
{{.app_env}}
{{- if .appEnv}}
{{.appEnv}}
{{- end}}
{{- if .plugins.lakebase}}
- name: PGHOST
value: "" # Copy from the Lakebase Postgres UI
- name: PGDATABASE
value: "databricks_postgres" # Copy from the Lakebase Postgres UI
- name: LAKEBASE_ENDPOINT
value: "" # Run: databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}
- name: PGSSLMODE
value: "require"
# - name: PGUSER
# value: "" # optional, defaults to DATABRICKS_CLIENT_ID
Comment on lines 1 to 16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is all very coupled to each plugin, right now the cli populates the env vars based on the resources from the manifest so we wouldn't need this for analytics.

I wonder if we can make it in a different way for lakebase so we can keep what we had instead of putting ifs all around checking for each plugin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you're right, we should use .appEnv. I'll change it 👍

env:
{{- if .appEnv}}
{{.appEnv}}
{{- end}}
{{- if .plugins.lakebase}}
  ... # additional, not resource-specific envs, until there is no resource we can use
{{- end}}

But for Lakebase, it is still be manual as I want to ensure there are comments near those envs for guidance. I don't see any better way to define this, unless there's a way on plugin manifest to provide env with additional comment - I don't think so? On the other hand, I don't think it makes sense to build it into the plugin manifest 🤔

Instead of putting ifs all around checking for each plugin

Please keep in mind that we'll do the ifs in the template anyway - at least for now. The more "dynamic" the template is, the more complex the structure and syntax is. In the current scale, IMO it's better to add routes / menu links based on if with a given plugin name, instead of having a slice and registering them dynamically which adds significant amount of complexity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Replaced with appEnv but still have the special Lakebase case)

{{- end}}
11 changes: 11 additions & 0 deletions template/appkit.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
"optional": []
}
},
"lakebase": {
"name": "lakebase",
"displayName": "Lakebase",
"description": "SQL query execution against Databricks Lakebase Autoscaling",
"package": "@databricks/appkit",
"resources": {
"required": [],
"optional": []
},
"onSetupMessage": "Configure environment variables before running or deploying the app.\nSee: https://databricks.github.io/appkit/docs/plugins/lakebase"
},
"server": {
"name": "server",
"displayName": "Server Plugin",
Expand Down
2 changes: 1 addition & 1 deletion template/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{.project_name}}</title>
<title>{{.projectName}}</title>
</head>
<body>
<div id="root"></div>
Expand Down
4 changes: 2 additions & 2 deletions template/client/public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "{{.project_name}}",
"short_name": "{{.project_name}}",
"name": "{{.projectName}}",
"short_name": "{{.projectName}}",
"icons": [
{
"src": "/favicon-192x192.png",
Expand Down
Loading