Skip to content

Commit 0344144

Browse files
authored
An example of a bundle that creates Lakebase database instance and catalog (#99)
1 parent 2a109e9 commit 0344144

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 data changes in the database instance, they 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+
* `psql` client version 14 or above (only needed to run the demo data generation)
13+
14+
## Usage
15+
16+
Modify `databricks.yml`:
17+
* Update the `host` field under `workspace` to the Databricks workspace to deploy to
18+
19+
Run `databricks bundle deploy` to deploy the bundle.
20+
21+
Please note that after this bundle gets deployed, the database instance starts running, which incurs cost.
22+
23+
Run the following queries to populate your database with sample data:
24+
25+
```bash
26+
# 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+
29+
# 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+
32+
# Show generated rows:
33+
databricks psql my-instance -- -d my_database -c "SELECT * FROM hello_world;"
34+
```
35+
36+
Open your catalog in Databricks: `databricks bundle open my_catalog`
37+
Navigate to the `public` schema, then to the `hello_world` table, then to "Sample data" and explore your generated data.
38+
39+
## Clean up
40+
To remove the provisioned instance and catalog run `databricks bundle destroy`
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
dev:
24+
# This target is for development purposes.
25+
# It defaults to the current Databricks workspace.
26+
default: true
27+
mode: development
28+

0 commit comments

Comments
 (0)