Skip to content

Commit ede4566

Browse files
bundle: Add postgres_databases resource (#5627)
## Changes Add `postgres_databases` (Lakebase Postgres databases) as a bundle resource for both the direct and Terraform engines: config type, direct-engine CRUD, Terraform converter, JSON schema, test-server handlers, and tests. Pairs with `postgres_roles` ([#5467](#5467)): a database is owned by a Postgres role, so the create API requires `spec.role`. - `parent` and `database_id` are recreate-only; the spec fields `postgres_database` / `role` update in place. - Drift detection for spec fields does not work until the backend returns `spec` on GET (it currently returns only `status`). ## Tests - Unit and acceptance tests (`basic`, `update`, `recreate`, `bind`, `live_errors`). - Verified against a real workspace: the acceptance suite passes on both engines, and manual checks of the create error paths (missing `role`, duplicate create) pass. This pull request and its description were written by Isaac. --------- Co-authored-by: Jan Rose <jan.rose@databricks.com>
1 parent 5fad697 commit ede4566

89 files changed

Lines changed: 2859 additions & 32 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NEXT_CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* engine/direct: Fix WAL corruption after two consecutive failed deploys ([#5606](https://github.com/databricks/cli/pull/5606)).
2222
* engine/direct: Don't open the deployment state WAL when a deploy's plan fails ([#5607](https://github.com/databricks/cli/pull/5607)).
2323
* Ignore unity catalog managed schema property defaults to avoid unnecessary drift ([#5195](https://github.com/databricks/cli/pull/5195)).
24-
* Add Postgres role as a bundle resource ([#5467](https://github.com/databricks/cli/pull/5467)).
24+
* Add `postgres_roles` and `postgres_databases` resources to create Postgres roles and databases on a Lakebase branch ([#5467](https://github.com/databricks/cli/pull/5467), [#5627](https://github.com/databricks/cli/pull/5627)).
2525
* direct: Stop spurious recreate/rename on redeploy when the backend normalizes a resource's name-based ID (e.g. Unity Catalog lowercasing a schema or volume name) ([#5599](https://github.com/databricks/cli/pull/5599)).
2626
* Fix the generated pipeline README to suggest `databricks bundle run <pipeline> --refresh <table>` for running a single transformation; the previously documented `--select` flag is not supported by `bundle run` ([#5252](https://github.com/databricks/cli/issues/5252)).
2727

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bundle:
2+
name: test-bundle
3+
4+
resources:
5+
postgres_databases:
6+
database1:
7+
parent: projects/test-project/branches/main
8+
database_id: test-database
9+
postgres_database: app_db

acceptance/bundle/deployment/bind/postgres_database/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
>>> [CLI] bundle deployment bind database1 projects/test-project/branches/main/databases/test-database --auto-approve
3+
Updating deployment state...
4+
Successfully bound postgres_database with an id 'projects/test-project/branches/main/databases/test-database'
5+
Run 'bundle deploy' to deploy changes to your workspace
6+
7+
>>> [CLI] bundle summary
8+
Name: test-bundle
9+
Target: default
10+
Workspace:
11+
User: [USERNAME]
12+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
13+
Resources:
14+
Postgres databases:
15+
database1:
16+
Name:
17+
URL: (not deployed)
18+
19+
>>> [CLI] bundle deployment unbind database1
20+
Updating deployment state...
21+
22+
>>> [CLI] bundle summary
23+
Name: test-bundle
24+
Target: default
25+
Workspace:
26+
User: [USERNAME]
27+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
28+
Resources:
29+
Postgres databases:
30+
database1:
31+
Name:
32+
URL: (not deployed)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DATABASE_NAME="projects/test-project/branches/main/databases/test-database"
2+
trace $CLI bundle deployment bind database1 "${DATABASE_NAME}" --auto-approve
3+
trace $CLI bundle summary
4+
5+
trace $CLI bundle deployment unbind database1
6+
trace $CLI bundle summary
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Local = true
2+
Cloud = false
3+
4+
Ignore = [
5+
".databricks"
6+
]
7+
8+
[[Server]]
9+
Pattern = "GET /api/2.0/postgres/projects/test-project/branches/main/databases/test-database"
10+
Response.Body = '''
11+
{
12+
"name": "projects/test-project/branches/main/databases/test-database",
13+
"parent": "projects/test-project/branches/main",
14+
"status": {
15+
"postgres_database": "app_db"
16+
}
17+
}
18+
'''
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
postgres_projects:
6+
project:
7+
project_id: test-pg-project-$UNIQUE_NAME
8+
display_name: Test Postgres Project
9+
10+
postgres_branches:
11+
branch:
12+
parent: ${resources.postgres_projects.project.name}
13+
branch_id: test-branch-$UNIQUE_NAME
14+
no_expiry: true
15+
16+
postgres_roles:
17+
owner:
18+
parent: ${resources.postgres_branches.branch.name}
19+
role_id: test-role-$UNIQUE_NAME
20+
postgres_role: app_role
21+
22+
postgres_databases:
23+
foo:
24+
parent: ${resources.postgres_branches.branch.name}
25+
database_id: test-database-$UNIQUE_NAME
26+
postgres_database: app_db
27+
role: ${resources.postgres_roles.owner.name}

acceptance/bundle/invariant/continue_293/out.test.toml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/invariant/migrate/out.test.toml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/invariant/no_drift/out.test.toml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)