Skip to content

Commit 928eb4c

Browse files
committed
An example of a bundle that creates Lakebase database instance and catalog
1 parent 51b8714 commit 928eb4c

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# OLTP database instance with a catalog
2+
3+
This example demonstrates how to define an OLTP database instance and a database catalog in a Databricks Asset Bundle.
4+
5+
It includes and deploys an example database instance and a catalog. When the instance is making changes to the database, the changes are reflected in Unity Catalog.
6+
7+
For more information about Databricks database instances, see the [documentation](https://docs.databricks.com/aws/en/oltp/).
8+
9+
## Prerequisites
10+
11+
* Databricks CLI v0.265.0 or above
12+
13+
## Usage
14+
15+
Modify `databricks.yml`:
16+
* Update the `host` field under `workspace` to the Databricks workspace to deploy to
17+
18+
Run `databricks bundle deploy` to deploy the bundle.
19+
20+
Run the following queries to populate your database with sample data:
21+
22+
- `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);"`
23+
- `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);"`
24+
- `databricks psql my-instance -- -d my_database -c "SELECT * FROM hello_world;"`
25+
26+
Open your catalog in Databricks Workspace to explore generated data in Unity Catalog: `databricks bundle open my_catalog`
27+
Navigate to `public` schema, then to `hello_world` table, then to "Sample data"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
bundle:
2+
name: database-catalog-example
3+
4+
# workspace:
5+
# host: https://myworkspace.cloud.databricks.com
6+
7+
resources:
8+
database_instances:
9+
my_instance:
10+
name: my-instance
11+
capacity: CU_1
12+
database_catalogs:
13+
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
18+
19+
20+
# Defines the targets for this bundle.
21+
# Targets allow you to deploy the same bundle to different Databricks workspaces.
22+
targets:
23+
prod: {
24+
# No overrides
25+
}
26+
dev:
27+
# This target is for development purposes.
28+
# It defaults to the current Databricks workspace.
29+
default: true
30+
mode: development
31+

0 commit comments

Comments
 (0)