Skip to content

Migrate Lakebase bundle examples to Postgres projects#161

Merged
janniklasrose merged 2 commits into
mainfrom
janniklasrose/lakebase-examples
Jul 1, 2026
Merged

Migrate Lakebase bundle examples to Postgres projects#161
janniklasrose merged 2 commits into
mainfrom
janniklasrose/lakebase-examples

Conversation

@janniklasrose

Copy link
Copy Markdown
Contributor

What

Migrate both knowledge_base Lakebase examples from the legacy database_instances / database_catalogs bundle resources to the Lakebase Autoscaling postgres_projects / postgres_catalogs resources.

  • database_with_catalog — switch databricks.yml to postgres_projects + postgres_catalogs; refresh the README (terminology, databricks psql --project ..., CLI v1.0.0).
  • app_with_database — replace mydb.database.yml with mydb.postgres.yml; wire the app to the new resources; refresh the README.

The app_with_database fix

The app attaches to the Postgres database by its resource path projects/<id>/branches/<branch>/databases/<database_id>. Relying on the catalog's create_database_if_missing: true creates the database with an auto-generated, unstable database_id, so the app has no stable path to reference — deploy fails repeatably with:

Database projects/.../databases/example_database does not exist in postgres branch ... (404)

Fix: declare the database explicitly as a postgres_databases resource (with an owner postgres_roles, which the CreateDatabase API requires) so it has a stable database_id, and point the app's postgres resource at ${resources.postgres_databases.my_database.id}. Note that database_id must be hyphenated (^[a-z][a-z0-9-]*) while postgres_database is the underscore-friendly Postgres database name.

database_with_catalog intentionally keeps create_database_if_missing — it has no app that needs a stable reference and is queried via psql by database name.

Verification

Deployed app_with_database end-to-end on staging: the bundle deploys all resources, databricks bundle run my_app reaches "App started successfully" (the app provisions its holidays.holiday_requests schema + demo data at import time), and databricks bundle destroy tears everything down. Confirmed no Lakebase projects left running afterward.

🤖 Generated with Claude Code

janniklasrose and others added 2 commits July 1, 2026 08:50
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>
The postgres_databases and postgres_roles resources this example now uses
first shipped in Databricks CLI v1.4.0 (databricks/cli#5467 and
databricks/cli#5627), so v1.0.0 is too low. database_with_catalog keeps
v1.0.0, since postgres_catalogs shipped in v1.0.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@janniklasrose janniklasrose requested a review from pietern July 1, 2026 07:41
@janniklasrose janniklasrose enabled auto-merge (squash) July 1, 2026 07:51

# Declare the database explicitly so it has a stable id that the app can
# reference. Relying on the catalog's create_database_if_missing would create a
# database with an auto-generated id, which the app cannot reference by path.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't create_database_if_missing produce a stable name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Btw, there is also an auto-created database called databricks_postgres (or with dash for the API name).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

name is stable, but the app attaches to the database by its resource path:

projects//branches//databases/<database_id>

with create_database_if_missing the resource isn't addressable

@janniklasrose janniklasrose merged commit 7454814 into main Jul 1, 2026
1 check passed
@janniklasrose janniklasrose deleted the janniklasrose/lakebase-examples branch July 1, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants