Skip to content

Commit 68de4e1

Browse files
janniklasroseclaude
andcommitted
Migrate Lakebase bundle examples to Postgres projects
Update both knowledge_base Lakebase examples from the legacy database_instances / database_catalogs resources to the Lakebase Autoscaling postgres_projects / postgres_catalogs resources, and refresh their READMEs (terminology, `databricks psql --project`, CLI v1.0.0). In app_with_database, declare the Postgres database explicitly via a postgres_databases resource (with an owner postgres_roles) so the app can reference it by a stable id. Relying on the catalog's create_database_if_missing creates a database with an auto-generated database_id that the app cannot address by path, so the app's postgres resource now points at ${resources.postgres_databases.my_database.id}. Verified end-to-end on staging: the bundle deploys, the app starts and provisions its schema and demo data, and `databricks bundle destroy` tears everything down. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent baeef18 commit 68de4e1

6 files changed

Lines changed: 67 additions & 41 deletions

File tree

knowledge_base/app_with_database/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
# Databricks app with OLTP database
22

33
This example demonstrates how to define a Databricks app backed by
4-
an OLTP Postgres in a bundle.
4+
a Lakebase Autoscaling Postgres database in a bundle.
55

6-
It includes and deploys an example application that uses Python and Dash and a database instance.
7-
When application is started it provisions its own schema and demonstration data in the OLTP database.
6+
It includes and deploys an example application that uses Python and Dash and a Lakebase database project.
7+
When application is started it provisions its own schema and demonstration data in the Postgres database.
88

99
For more information about Databricks Apps see the [documentation](https://docs.databricks.com/aws/en/dev-tools/databricks-apps).
10-
For more information about Databricks database instances see the [documentation](https://docs.databricks.com/aws/en/oltp/).
10+
For more information about Lakebase see the [documentation](https://docs.databricks.com/aws/en/oltp/).
11+
For more information about managing Lakebase with bundles see the [documentation](https://docs.databricks.com/aws/en/oltp/projects/manage-with-bundles).
1112

1213
## Prerequisites
1314

14-
* Databricks CLI v0.267.0 or above
15+
* Databricks CLI v1.0.0 or above
1516

1617
## Usage
1718

1819
1. Deploy the bundle:
1920
```
2021
databricks bundle deploy -t dev
2122
```
22-
Please note that after this bundle gets deployed, the database instance starts running immediately, which incurs cost.
23+
Please note that after this bundle is deployed, the Lakebase project is created and incurs cost while running. Lakebase Autoscaling scales its compute down to zero when idle.
2324

2425
2. Run the app:
2526
```
@@ -38,7 +39,7 @@ Alternatively, run `databricks bundle summary` to display its URL.
3839

3940
Run the following command to display the data generated by the app:
4041
```
41-
databricks psql example-database-instance -- --dbname example_database -c "select * from holidays.holiday_requests"
42+
databricks psql --project example-database -- --dbname example_database -c "select * from holidays.holiday_requests"
4243
```
4344

4445
5. Explore the app data:
@@ -48,7 +49,7 @@ databricks bundle open my_catalog
4849
```
4950

5051
## Clean up
51-
To remove the provisioned resources run
52+
To remove the deployed resources run
5253
```
5354
databricks bundle destroy
5455
```

knowledge_base/app_with_database/resources/myapp.app.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resources:
88
resources:
99
- name: "app-db"
1010
description: "A database for the app to be able to connect to and query"
11-
database:
12-
database_name: ${resources.database_catalogs.my_catalog.database_name}
13-
instance_name: ${resources.database_catalogs.my_catalog.database_instance_name}
11+
postgres:
12+
branch: ${resources.postgres_projects.my_project.id}/branches/production
13+
database: ${resources.postgres_databases.my_database.id}
1414
permission: "CAN_CONNECT_AND_CREATE"

knowledge_base/app_with_database/resources/mydb.database.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resources:
2+
postgres_projects:
3+
my_project:
4+
project_id: example-database
5+
display_name: "Example app database"
6+
pg_version: 16
7+
8+
# An owner role for the database. Lakebase requires a role when creating a
9+
# database, and declaring it explicitly keeps the bundle portable across users
10+
# (the auto-created project-owner role's id is derived from the creator's
11+
# identity).
12+
postgres_roles:
13+
my_role:
14+
parent: ${resources.postgres_projects.my_project.id}/branches/production
15+
role_id: app-owner
16+
postgres_role: app_owner
17+
18+
# Declare the database explicitly so it has a stable id that the app can
19+
# reference. Relying on the catalog's create_database_if_missing would create a
20+
# database with an auto-generated id, which the app cannot reference by path.
21+
postgres_databases:
22+
my_database:
23+
parent: ${resources.postgres_projects.my_project.id}/branches/production
24+
database_id: example-database
25+
postgres_database: example_database
26+
role: ${resources.postgres_roles.my_role.id}
27+
28+
# A Unity Catalog catalog backed by the Postgres database, so its data can be
29+
# browsed in Unity Catalog.
30+
postgres_catalogs:
31+
my_catalog:
32+
catalog_id: example_database_catalog
33+
branch: ${resources.postgres_projects.my_project.id}/branches/production
34+
postgres_database: ${resources.postgres_databases.my_database.postgres_database}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
# OLTP database instance with a catalog
1+
# Lakebase database project with a catalog
22

3-
This Declarative Automation Bundles example demonstrates how to define an OLTP database instance and a database catalog.
3+
This Declarative Automation Bundles example demonstrates how to define a Lakebase Autoscaling database project and a Unity Catalog catalog backed by it.
44

5-
It includes and deploys an example database instance and a catalog. When data changes in the database instance, they are reflected in Unity Catalog.
5+
It includes and deploys an example project and a catalog. When data changes in the project's Postgres database, it is reflected in Unity Catalog.
66

7-
For more information about Databricks database instances, see the [documentation](https://docs.databricks.com/aws/en/oltp/).
7+
For more information about Lakebase, see the [documentation](https://docs.databricks.com/aws/en/oltp/).
8+
For more information about managing Lakebase with bundles, see the [documentation](https://docs.databricks.com/aws/en/oltp/projects/manage-with-bundles).
89

910
## Prerequisites
1011

11-
* Databricks CLI v0.265.0 or above
12+
* Databricks CLI v1.0.0 or above
1213
* `psql` client version 14 or above (only needed to run the demo data generation)
1314

1415
## Usage
@@ -18,23 +19,23 @@ Modify `databricks.yml`:
1819

1920
Run `databricks bundle deploy` to deploy the bundle.
2021

21-
Please note that after this bundle gets deployed, the database instance starts running, which incurs cost.
22+
Please note that after this bundle is deployed, the Lakebase project is created and incurs cost while running. Lakebase Autoscaling scales its compute down to zero when idle.
2223

2324
Run the following queries to populate your database with sample data:
2425

2526
```bash
2627
# Create a demo table:
27-
databricks psql my-instance -- -d my_database -c "CREATE TABLE IF NOT EXISTS hello_world (id SERIAL PRIMARY KEY, message TEXT, number INTEGER, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"
28+
databricks psql --project my-project -- -d my_database -c "CREATE TABLE IF NOT EXISTS hello_world (id SERIAL PRIMARY KEY, message TEXT, number INTEGER, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"
2829

2930
# Insert 100 rows of demo data:
30-
databricks psql my-instance -- -d my_database -c "INSERT INTO hello_world (message, number) SELECT 'Hello World #' || generate_series, generate_series FROM generate_series(1, 100);"
31+
databricks psql --project my-project -- -d my_database -c "INSERT INTO hello_world (message, number) SELECT 'Hello World #' || generate_series, generate_series FROM generate_series(1, 100);"
3132

3233
# Show generated rows:
33-
databricks psql my-instance -- -d my_database -c "SELECT * FROM hello_world;"
34+
databricks psql --project my-project -- -d my_database -c "SELECT * FROM hello_world;"
3435
```
3536

3637
Open your catalog in Databricks: `databricks bundle open my_catalog`
3738
Navigate to the `public` schema, then to the `hello_world` table, then to "Sample data" and explore your generated data.
3839

3940
## Clean up
40-
To remove the provisioned instance and catalog run `databricks bundle destroy`
41+
To remove the project and catalog run `databricks bundle destroy`

knowledge_base/database_with_catalog/databricks.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ bundle:
55
# host: https://myworkspace.cloud.databricks.com
66

77
resources:
8-
database_instances:
9-
my_instance:
10-
name: my-instance
11-
capacity: CU_1
12-
database_catalogs:
8+
postgres_projects:
9+
my_project:
10+
project_id: my-project
11+
display_name: "Example project"
12+
pg_version: 16
13+
postgres_catalogs:
1314
my_catalog:
14-
database_instance_name: ${resources.database_instances.my_instance.name}
15-
name: example_catalog
16-
database_name: my_database
17-
create_database_if_not_exists: true
15+
catalog_id: example_catalog
16+
branch: ${resources.postgres_projects.my_project.id}/branches/production
17+
postgres_database: my_database
18+
create_database_if_missing: true
1819

1920

2021
# Defines the targets for this bundle.

0 commit comments

Comments
 (0)