From e9cfd89628598d3cf3e7f1495461578c7959a29f Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 19 Nov 2026 13:54:31 +0000 Subject: [PATCH 1/2] acc: cover field removals on postgres resources against the real API Bundle tests for removing a field from each postgres resource, plus a raw-API factcheck showing how each Update API clears a field under a field mask and under update_mask=spec. The testserver now matches what the real API did on 2026-11-19 for these requests. Co-authored-by: Isaac --- .../remove_is_protected/databricks.yml.tmpl | 20 +++ .../remove_is_protected/out.deploy.remove.txt | 11 ++ .../remove_is_protected/out.get.remove.json | 3 + .../out.plan.after_remove.json | 10 ++ .../remove_is_protected/out.plan.remove.json | 10 ++ .../out.requests.remove.json | 12 ++ .../remove_is_protected/out.test.toml | 2 + .../remove_is_protected/output.txt | 33 +++++ .../remove_is_protected/script | 29 ++++ .../remove_is_protected/test.toml | 4 + .../remove_disabled/databricks.yml.tmpl | 28 ++++ .../remove_disabled/out.deploy.remove.txt | 11 ++ .../remove_disabled/out.get.remove.json | 3 + .../out.plan.after_remove.json | 10 ++ .../remove_disabled/out.plan.remove.json | 10 ++ .../remove_disabled/out.requests.remove.json | 14 ++ .../remove_disabled/out.test.toml | 2 + .../remove_disabled/output.txt | 35 +++++ .../postgres_endpoints/remove_disabled/script | 28 ++++ .../remove_disabled/test.toml | 4 + .../databricks.yml.tmpl | 31 ++++ .../out.deploy.remove.txt | 4 + .../out.get.remove.json | 7 + .../out.plan.after_remove.json | 4 + .../out.plan.remove.json | 10 ++ .../out.requests.remove.json | 19 +++ .../remove_pg_settings_key/out.test.toml | 2 + .../remove_pg_settings_key/output.txt | 40 ++++++ .../remove_pg_settings_key/script | 28 ++++ .../factcheck/clear_field/out.test.toml | 2 + .../factcheck/clear_field/output.txt | 72 ++++++++++ .../factcheck/clear_field/script | 90 ++++++++++++ .../remove_custom_tags/databricks.yml.tmpl | 18 +++ .../remove_custom_tags/out.deploy.shrink.txt | 4 + .../remove_custom_tags/out.get.shrink.json | 8 ++ .../out.plan.after_shrink.json | 11 ++ .../remove_custom_tags/out.plan.shrink.json | 40 ++++++ .../out.requests.shrink.json | 20 +++ .../remove_custom_tags/out.test.toml | 2 + .../remove_custom_tags/output.txt | 59 ++++++++ .../remove_custom_tags/script | 32 +++++ .../databricks.yml.tmpl | 17 +++ .../out.deploy.remove.txt | 4 + .../out.get.remove.json | 5 + .../out.plan.after_remove.json | 11 ++ .../out.plan.remove.json | 16 +++ .../out.requests.remove.json | 19 +++ .../out.test.toml | 2 + .../remove_default_pg_settings_key/output.txt | 30 ++++ .../remove_default_pg_settings_key/script | 28 ++++ .../databricks.yml.tmpl | 14 ++ .../out.deploy.remove.txt | 11 ++ .../out.get.remove.json | 3 + .../out.plan.after_remove.json | 16 +++ .../out.plan.remove.json | 16 +++ .../out.requests.remove.json | 14 ++ .../out.test.toml | 2 + .../remove_enable_pg_native_login/output.txt | 27 ++++ .../remove_enable_pg_native_login/script | 28 ++++ .../remove_enable_pg_native_login/test.toml | 4 + .../remove_attribute/databricks.yml.tmpl | 28 ++++ .../remove_attribute/out.deploy.remove.txt | 11 ++ .../remove_attribute/out.get.remove.json | 7 + .../out.plan.after_remove.json | 16 +++ .../remove_attribute/out.plan.remove.json | 16 +++ .../remove_attribute/out.requests.remove.json | 15 ++ .../remove_attribute/out.test.toml | 2 + .../remove_attribute/output.txt | 39 +++++ .../postgres_roles/remove_attribute/script | 28 ++++ .../postgres_roles/remove_attribute/test.toml | 4 + .../databricks.yml.tmpl | 27 ++++ .../out.deploy.remove.txt | 4 + .../out.get.remove.json | 3 + .../out.plan.after_remove.json | 11 ++ .../out.plan.remove.json | 20 +++ .../out.requests.remove.json | 12 ++ .../remove_membership_roles/out.test.toml | 2 + .../remove_membership_roles/output.txt | 37 +++++ .../remove_membership_roles/script | 28 ++++ libs/testserver/postgres.go | 135 +++++++++++++++--- libs/testserver/postgres_spec.go | 5 +- 81 files changed, 1478 insertions(+), 21 deletions(-) create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/output.txt create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/script create mode 100644 acceptance/bundle/resources/postgres_branches/remove_is_protected/test.toml create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/output.txt create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/script create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_disabled/test.toml create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/output.txt create mode 100644 acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/script create mode 100644 acceptance/bundle/resources/postgres_projects/factcheck/clear_field/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_projects/factcheck/clear_field/output.txt create mode 100644 acceptance/bundle/resources/postgres_projects/factcheck/clear_field/script create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.shrink.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_shrink.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/script create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/output.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/script create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/output.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/script create mode 100644 acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/test.toml create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/output.txt create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/script create mode 100644 acceptance/bundle/resources/postgres_roles/remove_attribute/test.toml create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.requests.remove.json create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.test.toml create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/output.txt create mode 100644 acceptance/bundle/resources/postgres_roles/remove_membership_roles/script diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_branches/remove_is_protected/databricks.yml.tmpl new file mode 100644 index 00000000000..fb39cb54d48 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/databricks.yml.tmpl @@ -0,0 +1,20 @@ +bundle: + name: remove-is-protected-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Branch Protection Removal" + pg_version: 16 + history_retention_duration: 604800s + + postgres_branches: + main: + parent: ${resources.postgres_projects.my_project.id} + branch_id: main + no_expiry: true + is_protected: true diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.deploy.remove.txt new file mode 100644 index 00000000000..2f95fba323e --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.deploy.remove.txt @@ -0,0 +1,11 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-is-protected-[UNIQUE_NAME]/default/files... +Error: cannot update resources.postgres_branches.main: updating id=projects/test-pg-proj-[UNIQUE_NAME]/branches/main: Field 'spec.is_protected' is in update_mask but not provided in request (400 INVALID_PARAMETER_VALUE) + +Endpoint: PATCH [DATABRICKS_URL]/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main?update_mask=spec.is_protected +HTTP Status: 400 Bad Request +API error_code: INVALID_PARAMETER_VALUE +API message: Field 'spec.is_protected' is in update_mask but not provided in request + +Files: 0 uploaded, 0 deleted + +Exit code: 1 diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.get.remove.json b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.get.remove.json new file mode 100644 index 00000000000..f7e6da99577 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.get.remove.json @@ -0,0 +1,3 @@ +{ + "is_protected": true +} diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.after_remove.json new file mode 100644 index 00000000000..591fb1bf72f --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.after_remove.json @@ -0,0 +1,10 @@ +{ + "action": "update", + "changes": { + "is_protected": { + "action": "update", + "old": true, + "remote": true + } + } +} diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.remove.json b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.remove.json new file mode 100644 index 00000000000..591fb1bf72f --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.plan.remove.json @@ -0,0 +1,10 @@ +{ + "action": "update", + "changes": { + "is_protected": { + "action": "update", + "old": true, + "remote": true + } + } +} diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.requests.remove.json b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.requests.remove.json new file mode 100644 index 00000000000..caf851359d1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.requests.remove.json @@ -0,0 +1,12 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main", + "q": { + "update_mask": "spec.is_protected" + }, + "body": { + "spec": { + "no_expiry": true + } + } +} diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.test.toml b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/output.txt b/acceptance/bundle/resources/postgres_branches/remove_is_protected/output.txt new file mode 100644 index 00000000000..c7259b66324 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/output.txt @@ -0,0 +1,33 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-is-protected-[UNIQUE_NAME]/default/files... +Created postgres_branches.main +Created postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-branch projects/test-pg-proj-[UNIQUE_NAME]/branches/main +{ + "is_protected": true +} + +=== Remove is_protected: true + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_branches.main + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase branches. +All data stored in them will be permanently lost: + delete resources.postgres_branches.main + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-is-protected-[UNIQUE_NAME]/default + +Destroy: 2 deleted diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/script b/acceptance/bundle/resources/postgres_branches/remove_is_protected/script new file mode 100644 index 00000000000..c3813a6fca6 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/script @@ -0,0 +1,29 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + $CLI postgres update-branch "projects/test-pg-proj-${UNIQUE_NAME}/branches/main" spec.is_protected --json '{"spec": {"is_protected": false}}' &> LOG.unprotect || true + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# is_protected is a bool that defaults to false: remove it after setting it to true. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_branches.main" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-branch "projects/test-pg-proj-${UNIQUE_NAME}/branches/main" | jq '.status | {is_protected}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_branches.main" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-branch "projects/test-pg-proj-${UNIQUE_NAME}/branches/main" | jq '.status | {is_protected}' + +title "Remove is_protected: true" +update_file.py databricks.yml "$(printf ' is_protected: true\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_branches/remove_is_protected/test.toml b/acceptance/bundle/resources/postgres_branches/remove_is_protected/test.toml new file mode 100644 index 00000000000..1a4dd03a752 --- /dev/null +++ b/acceptance/bundle/resources/postgres_branches/remove_is_protected/test.toml @@ -0,0 +1,4 @@ +# Verified against a real workspace on 2026-11-19: the direct engine masks spec.is_protected and omits it from +# the body, and the API rejects a masked scalar with no value. The old value stays in state, so +# out.plan.after_remove.json shows the removal pending again and every later deploy fails the same way. +Badness = "Removing is_protected fails: the field is named in update_mask but omitted from the body, which the API rejects" diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/databricks.yml.tmpl new file mode 100644 index 00000000000..1f569eb5f02 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/databricks.yml.tmpl @@ -0,0 +1,28 @@ +bundle: + name: remove-disabled-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Endpoint Disabled Removal" + pg_version: 16 + history_retention_duration: 604800s + + postgres_branches: + main: + parent: ${resources.postgres_projects.my_project.id} + branch_id: main + no_expiry: true + + postgres_endpoints: + my_endpoint: + parent: ${resources.postgres_branches.main.id} + endpoint_id: my-endpoint + endpoint_type: ENDPOINT_TYPE_READ_ONLY + autoscaling_limit_min_cu: 0.5 + autoscaling_limit_max_cu: 2 + disabled: true diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.deploy.remove.txt new file mode 100644 index 00000000000..32e0b51b6fb --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.deploy.remove.txt @@ -0,0 +1,11 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-disabled-[UNIQUE_NAME]/default/files... +Error: cannot update resources.postgres_endpoints.my_endpoint: updating id=projects/test-pg-proj-[UNIQUE_NAME]/branches/main/endpoints/my-endpoint: Field 'spec.disabled' is in update_mask but not provided in request (400 INVALID_PARAMETER_VALUE) + +Endpoint: PATCH [DATABRICKS_URL]/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/endpoints/my-endpoint?update_mask=spec.disabled +HTTP Status: 400 Bad Request +API error_code: INVALID_PARAMETER_VALUE +API message: Field 'spec.disabled' is in update_mask but not provided in request + +Files: 0 uploaded, 0 deleted + +Exit code: 1 diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.get.remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.get.remove.json new file mode 100644 index 00000000000..f44bc997a0e --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.get.remove.json @@ -0,0 +1,3 @@ +{ + "disabled": true +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.after_remove.json new file mode 100644 index 00000000000..a3b8a4be73c --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.after_remove.json @@ -0,0 +1,10 @@ +{ + "action": "update", + "changes": { + "disabled": { + "action": "update", + "old": true, + "remote": true + } + } +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.remove.json new file mode 100644 index 00000000000..a3b8a4be73c --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.plan.remove.json @@ -0,0 +1,10 @@ +{ + "action": "update", + "changes": { + "disabled": { + "action": "update", + "old": true, + "remote": true + } + } +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.requests.remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.requests.remove.json new file mode 100644 index 00000000000..4da029e78eb --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.requests.remove.json @@ -0,0 +1,14 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/endpoints/my-endpoint", + "q": { + "update_mask": "spec.disabled" + }, + "body": { + "spec": { + "autoscaling_limit_max_cu": 2, + "autoscaling_limit_min_cu": 0.5, + "endpoint_type": "ENDPOINT_TYPE_READ_ONLY" + } + } +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.test.toml b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/output.txt b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/output.txt new file mode 100644 index 00000000000..42e8a67291c --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/output.txt @@ -0,0 +1,35 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-disabled-[UNIQUE_NAME]/default/files... +Created postgres_branches.main +Created postgres_endpoints.my_endpoint +Created postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-endpoint projects/test-pg-proj-[UNIQUE_NAME]/branches/main/endpoints/my-endpoint +{ + "disabled": true +} + +=== Remove disabled: true + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_branches.main + delete resources.postgres_endpoints.my_endpoint + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase branches. +All data stored in them will be permanently lost: + delete resources.postgres_branches.main + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-disabled-[UNIQUE_NAME]/default + +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/script b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/script new file mode 100644 index 00000000000..a9d4a41676b --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/script @@ -0,0 +1,28 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# disabled is a bool that defaults to false: remove it after setting it to true. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-endpoint "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/endpoints/my-endpoint" | jq '.status | {disabled}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-endpoint "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/endpoints/my-endpoint" | jq '.status | {disabled}' + +title "Remove disabled: true" +update_file.py databricks.yml "$(printf ' disabled: true\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_disabled/test.toml b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/test.toml new file mode 100644 index 00000000000..0b54b7620da --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_disabled/test.toml @@ -0,0 +1,4 @@ +# Verified against a real workspace on 2026-11-19: the direct engine masks spec.disabled and omits it from +# the body, and the API rejects a masked scalar with no value. The old value stays in state, so +# out.plan.after_remove.json shows the removal pending again and every later deploy fails the same way. +Badness = "Removing disabled fails: the field is named in update_mask but omitted from the body, which the API rejects" diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/databricks.yml.tmpl new file mode 100644 index 00000000000..2768f365770 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/databricks.yml.tmpl @@ -0,0 +1,31 @@ +bundle: + name: remove-pg-settings-key-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Endpoint pg_settings Key Removal" + pg_version: 16 + history_retention_duration: 604800s + + postgres_branches: + main: + parent: ${resources.postgres_projects.my_project.id} + branch_id: main + no_expiry: true + + postgres_endpoints: + my_endpoint: + parent: ${resources.postgres_branches.main.id} + endpoint_id: my-endpoint + endpoint_type: ENDPOINT_TYPE_READ_ONLY + autoscaling_limit_min_cu: 0.5 + autoscaling_limit_max_cu: 2 + settings: + pg_settings: + statement_timeout: "8000" + lock_timeout: "5000" diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.deploy.remove.txt new file mode 100644 index 00000000000..81a354d8f76 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.deploy.remove.txt @@ -0,0 +1,4 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-pg-settings-key-[UNIQUE_NAME]/default/files... +Updated postgres_endpoints.my_endpoint +Files: 0 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 2 unchanged diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.get.remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.get.remove.json new file mode 100644 index 00000000000..940fed680b8 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.get.remove.json @@ -0,0 +1,7 @@ +{ + "settings": { + "pg_settings": { + "statement_timeout": "8000" + } + } +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.after_remove.json new file mode 100644 index 00000000000..6d36d78db61 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.after_remove.json @@ -0,0 +1,4 @@ +{ + "action": "skip", + "changes": null +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.remove.json new file mode 100644 index 00000000000..18834e47b93 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.plan.remove.json @@ -0,0 +1,10 @@ +{ + "action": "update", + "changes": { + "settings.pg_settings['lock_timeout']": { + "action": "update", + "old": "5000", + "remote": "5000" + } + } +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.requests.remove.json b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.requests.remove.json new file mode 100644 index 00000000000..c97e29d72e2 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.requests.remove.json @@ -0,0 +1,19 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/endpoints/my-endpoint", + "q": { + "update_mask": "spec.settings.pg_settings" + }, + "body": { + "spec": { + "autoscaling_limit_max_cu": 2, + "autoscaling_limit_min_cu": 0.5, + "endpoint_type": "ENDPOINT_TYPE_READ_ONLY", + "settings": { + "pg_settings": { + "statement_timeout": "8000" + } + } + } + } +} diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.test.toml b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/output.txt b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/output.txt new file mode 100644 index 00000000000..6148951d582 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/output.txt @@ -0,0 +1,40 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-pg-settings-key-[UNIQUE_NAME]/default/files... +Created postgres_branches.main +Created postgres_endpoints.my_endpoint +Created postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-endpoint projects/test-pg-proj-[UNIQUE_NAME]/branches/main/endpoints/my-endpoint +{ + "settings": { + "pg_settings": { + "lock_timeout": "5000", + "statement_timeout": "8000" + } + } +} + +=== Remove one of two settings.pg_settings keys + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_branches.main + delete resources.postgres_endpoints.my_endpoint + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase branches. +All data stored in them will be permanently lost: + delete resources.postgres_branches.main + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-pg-settings-key-[UNIQUE_NAME]/default + +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/script b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/script new file mode 100644 index 00000000000..6d7015f40c9 --- /dev/null +++ b/acceptance/bundle/resources/postgres_endpoints/remove_pg_settings_key/script @@ -0,0 +1,28 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# settings.pg_settings is a map: remove one of its two keys. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-endpoint "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/endpoints/my-endpoint" | jq '.status | {settings}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-endpoint "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/endpoints/my-endpoint" | jq '.status | {settings}' + +title "Remove one of two settings.pg_settings keys" +update_file.py databricks.yml "$(printf ' lock_timeout: "5000"\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/out.test.toml b/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/out.test.toml new file mode 100644 index 00000000000..b229e664117 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = [] diff --git a/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/output.txt b/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/output.txt new file mode 100644 index 00000000000..a6502b763cd --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/output.txt @@ -0,0 +1,72 @@ + +=== project enable_pg_native_login (bool) +update-project update_mask=spec.enable_pg_native_login body={"spec":{"enable_pg_native_login":true}} +update-project update_mask=spec.enable_pg_native_login body={"spec":{}} +Error: Field '[SPEC_FIELD]' is in update_mask but not provided in request + +Exit code: 1 +{"enable_pg_native_login":true} +update-project update_mask=spec.enable_pg_native_login body={"spec":{"enable_pg_native_login":true}} +update-project update_mask=spec body={"spec":{"display_name":"factcheck","pg_version":16}} +{"enable_pg_native_login":true} +update-project update_mask=spec.enable_pg_native_login body={"spec":{"enable_pg_native_login":true}} +update-project update_mask=spec body={"spec":{"display_name":"factcheck","pg_version":16,"enable_pg_native_login":false}} +{"enable_pg_native_login":false} + +=== project custom_tags (repeated) +update-project update_mask=spec.custom_tags body={"spec":{"custom_tags":[{"key":"team","value":"data"}]}} +update-project update_mask=spec.custom_tags body={"spec":{}} +{"custom_tags":null} +update-project update_mask=spec.custom_tags body={"spec":{"custom_tags":[{"key":"team","value":"data"}]}} +update-project update_mask=spec body={"spec":{"display_name":"factcheck","pg_version":16}} +{"custom_tags":[{"key":"team","value":"data"}]} + +=== branch is_protected (bool) +update-branch update_mask=spec.is_protected body={"spec":{"is_protected":true}} +update-branch update_mask=spec.is_protected body={"spec":{}} +Error: Field '[SPEC_FIELD]' is in update_mask but not provided in request + +Exit code: 1 +{"is_protected":true} +update-branch update_mask=spec.is_protected body={"spec":{"is_protected":true}} +update-branch update_mask=spec body={"spec":{"no_expiry":true}} +{"is_protected":true} +update-branch update_mask=spec.is_protected body={"spec":{"is_protected":true}} +update-branch update_mask=spec body={"spec":{"no_expiry":true,"is_protected":false}} +{"is_protected":false} + +=== endpoint disabled (bool) +update-endpoint update_mask=spec.disabled body={"spec":{"disabled":true}} +update-endpoint update_mask=spec.disabled body={"spec":{}} +Error: Field '[SPEC_FIELD]' is in update_mask but not provided in request + +Exit code: 1 +{"disabled":true} +update-endpoint update_mask=spec.disabled body={"spec":{"disabled":true}} +update-endpoint update_mask=spec body={"spec":{"endpoint_type":"ENDPOINT_TYPE_READ_WRITE"}} +{"disabled":true} +update-endpoint update_mask=spec.disabled body={"spec":{"disabled":true}} +update-endpoint update_mask=spec body={"spec":{"endpoint_type":"ENDPOINT_TYPE_READ_WRITE","disabled":false}} +{"disabled":false} + +=== role attributes.createdb (bool in a message) +update-role update_mask=spec.attributes.createdb body={"spec":{"attributes":{"createdb":true}}} +update-role update_mask=spec.attributes.createdb body={"spec":{"attributes":{}}} +Error: Field '[SPEC_FIELD]' is in update_mask but not provided in request + +Exit code: 1 +{"createdb":true} +update-role update_mask=spec.attributes.createdb body={"spec":{"attributes":{"createdb":true}}} +update-role update_mask=spec body={"spec":{"postgres_role":"factcheck_role","attributes":{}}} +{"createdb":true} +update-role update_mask=spec.attributes.createdb body={"spec":{"attributes":{"createdb":true}}} +update-role update_mask=spec body={"spec":{"postgres_role":"factcheck_role","attributes":{"createdb":false}}} +{"createdb":false} + +=== role membership_roles (repeated) +update-role update_mask=spec.membership_roles body={"spec":{"membership_roles":["DATABRICKS_SUPERUSER"]}} +update-role update_mask=spec.membership_roles body={"spec":{}} +{"membership_roles":null} +update-role update_mask=spec.membership_roles body={"spec":{"membership_roles":["DATABRICKS_SUPERUSER"]}} +update-role update_mask=spec body={"spec":{"postgres_role":"factcheck_role"}} +{"membership_roles":null} diff --git a/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/script b/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/script new file mode 100644 index 00000000000..8702bab83fa --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/factcheck/clear_field/script @@ -0,0 +1,90 @@ +# How the postgres Update APIs clear a field, via raw $CLI (no bundle). Each case sets +# a field, then clears it three ways: masking the field itself with the field omitted +# from the body, masking the whole spec with the field omitted, and masking the whole +# spec with the zero value sent explicitly. After each update the field is read back +# from status. +# +# The bundle removes a field from the config by omitting it from the body, so +# "omitted" is the shape that matters. Scalars cannot be cleared that way under either +# mask: the field mask is rejected, the spec mask leaves the value in place. Repeated +# fields are cleared by the field mask, while under the spec mask project custom_tags +# are kept but role membership_roles are cleared. +# +# Repeated fields have no explicit-zero case: the SDK drops an empty list from the +# body, so "custom_tags": [] sends the same request as omitting it. +# +# To run this outside the acceptance harness (against a real workspace), stub the +# harness-provided helpers, then `bash` this file: +# export CLI=databricks UNIQUE_NAME=$(date +%s) +# errcode() { "$@" || echo "Exit code: $?"; } +# title() { printf '\n=== %s\n' "$*"; } + +pid="factcheck-clear-${UNIQUE_NAME}" +project="projects/${pid}" +branch="${project}/branches/production" +endpoint="${branch}/endpoints/primary" +role="${branch}/roles/factcheck-role" + +cleanup() { + $CLI postgres delete-project "$project" --purge --no-wait &> LOG.cleanup || true +} +trap cleanup EXIT + +# update KIND NAME MASK BODY: send one update, report only whether it was accepted. +update() { + echo "update-$1 update_mask=$3 body=$4" + errcode $CLI postgres update-$1 "$2" "$3" --json "$4" > /dev/null +} + +$CLI postgres create-project "$pid" --json '{"spec":{"display_name":"factcheck","pg_version":16}}' &> LOG.create +$CLI postgres create-role "$branch" --role-id factcheck-role --json '{"spec":{"postgres_role":"factcheck_role"}}' &> LOG.create-role + +project_field() { $CLI postgres get-project "$project" | jq -c ".status | {$1}"; } +branch_field() { $CLI postgres get-branch "$branch" | jq -c ".status | {$1}"; } +endpoint_field() { $CLI postgres get-endpoint "$endpoint" | jq -c ".status | {$1}"; } +role_field() { $CLI postgres get-role "$role" | jq -c ".status | {$1}"; } + +title "project enable_pg_native_login (bool)" +P='"display_name":"factcheck","pg_version":16' +for clear in "spec.enable_pg_native_login|{\"spec\":{}}" "spec|{\"spec\":{$P}}" "spec|{\"spec\":{$P,\"enable_pg_native_login\":false}}"; do + update project "$project" spec.enable_pg_native_login '{"spec":{"enable_pg_native_login":true}}' + update project "$project" "${clear%%|*}" "${clear#*|}" + project_field enable_pg_native_login +done + +title "project custom_tags (repeated)" +for clear in "spec.custom_tags|{\"spec\":{}}" "spec|{\"spec\":{$P}}"; do + update project "$project" spec.custom_tags '{"spec":{"custom_tags":[{"key":"team","value":"data"}]}}' + update project "$project" "${clear%%|*}" "${clear#*|}" + project_field custom_tags +done + +title "branch is_protected (bool)" +for clear in "spec.is_protected|{\"spec\":{}}" "spec|{\"spec\":{\"no_expiry\":true}}" "spec|{\"spec\":{\"no_expiry\":true,\"is_protected\":false}}"; do + update branch "$branch" spec.is_protected '{"spec":{"is_protected":true}}' + update branch "$branch" "${clear%%|*}" "${clear#*|}" + branch_field is_protected +done + +title "endpoint disabled (bool)" +E='"endpoint_type":"ENDPOINT_TYPE_READ_WRITE"' +for clear in "spec.disabled|{\"spec\":{}}" "spec|{\"spec\":{$E}}" "spec|{\"spec\":{$E,\"disabled\":false}}"; do + update endpoint "$endpoint" spec.disabled '{"spec":{"disabled":true}}' + update endpoint "$endpoint" "${clear%%|*}" "${clear#*|}" + endpoint_field disabled +done + +title "role attributes.createdb (bool in a message)" +R='"postgres_role":"factcheck_role"' +for clear in "spec.attributes.createdb|{\"spec\":{\"attributes\":{}}}" "spec|{\"spec\":{$R,\"attributes\":{}}}" "spec|{\"spec\":{$R,\"attributes\":{\"createdb\":false}}}"; do + update role "$role" spec.attributes.createdb '{"spec":{"attributes":{"createdb":true}}}' + update role "$role" "${clear%%|*}" "${clear#*|}" + role_field 'createdb: .attributes.createdb' +done + +title "role membership_roles (repeated)" +for clear in "spec.membership_roles|{\"spec\":{}}" "spec|{\"spec\":{$R}}"; do + update role "$role" spec.membership_roles '{"spec":{"membership_roles":["DATABRICKS_SUPERUSER"]}}' + update role "$role" "${clear%%|*}" "${clear#*|}" + role_field membership_roles +done diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/databricks.yml.tmpl new file mode 100644 index 00000000000..bcf097ff4ee --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/databricks.yml.tmpl @@ -0,0 +1,18 @@ +bundle: + name: remove-custom-tags-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Custom Tags Removal" + pg_version: 16 + history_retention_duration: 604800s + custom_tags: + - key: env + value: test + - key: team + value: data diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.shrink.txt b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.shrink.txt new file mode 100644 index 00000000000..a283a1a7622 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.shrink.txt @@ -0,0 +1,4 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-custom-tags-[UNIQUE_NAME]/default/files... +Updated postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json new file mode 100644 index 00000000000..d00028e7eba --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json @@ -0,0 +1,8 @@ +{ + "custom_tags": [ + { + "key": "team", + "value": "data" + } + ] +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_shrink.json new file mode 100644 index 00000000000..6cf4670fe06 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_shrink.json @@ -0,0 +1,11 @@ +{ + "action": "skip", + "changes": { + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json new file mode 100644 index 00000000000..3f34994c75c --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json @@ -0,0 +1,40 @@ +{ + "action": "update", + "changes": { + "custom_tags": { + "action": "update", + "old": [ + { + "key": "env", + "value": "test" + }, + { + "key": "team", + "value": "data" + } + ], + "new": [ + { + "key": "team", + "value": "data" + } + ], + "remote": [ + { + "key": "env", + "value": "test" + }, + { + "key": "team", + "value": "data" + } + ] + }, + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json new file mode 100644 index 00000000000..88834ab339b --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json @@ -0,0 +1,20 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]", + "q": { + "update_mask": "spec.custom_tags" + }, + "body": { + "spec": { + "custom_tags": [ + { + "key": "team", + "value": "data" + } + ], + "display_name": "Test Project for Custom Tags Removal", + "history_retention_duration": "604800s", + "pg_version": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.test.toml b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt new file mode 100644 index 00000000000..e9defa22496 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt @@ -0,0 +1,59 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-custom-tags-[UNIQUE_NAME]/default/files... +Created postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-project projects/test-pg-proj-[UNIQUE_NAME] +{ + "custom_tags": [ + { + "key": "env", + "value": "test" + }, + { + "key": "team", + "value": "data" + } + ] +} + +=== Remove one of two custom_tags + +=== Remove the last custom_tag, leaving no custom_tags in the config +old=' custom_tags:\n - key: team\n value: data' not found in filename='databricks.yml' +bundle: + name: remove-custom-tags-[UNIQUE_NAME] + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-[UNIQUE_NAME] + display_name: "Test Project for Custom Tags Removal" + pg_version: 16 + history_retention_duration: 604800s + custom_tags: + + - key: team + value: data + + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-custom-tags-[UNIQUE_NAME]/default + +Destroy: 1 deleted + +Exit code: 1 diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script new file mode 100644 index 00000000000..388a7697892 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script @@ -0,0 +1,32 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# custom_tags is a repeated field: shrink it, then remove it entirely. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {custom_tags}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {custom_tags}' + +title "Remove one of two custom_tags" +update_file.py databricks.yml "$(printf ' - key: env\n value: test\n')" "" +step shrink + +title "Remove the last custom_tag, leaving no custom_tags in the config" +update_file.py databricks.yml "$(printf ' custom_tags:\n - key: team\n value: data\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/databricks.yml.tmpl new file mode 100644 index 00000000000..a64c161e447 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/databricks.yml.tmpl @@ -0,0 +1,17 @@ +bundle: + name: remove-default-pg-settings-key-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Default pg_settings Key Removal" + pg_version: 16 + history_retention_duration: 604800s + default_endpoint_settings: + pg_settings: + statement_timeout: "8000" + lock_timeout: "5000" diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.deploy.remove.txt new file mode 100644 index 00000000000..1f0698e9798 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.deploy.remove.txt @@ -0,0 +1,4 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-default-pg-settings-key-[UNIQUE_NAME]/default/files... +Updated postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.get.remove.json b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.get.remove.json new file mode 100644 index 00000000000..f8687c57ad0 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.get.remove.json @@ -0,0 +1,5 @@ +{ + "pg_settings": { + "statement_timeout": "8000" + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.after_remove.json new file mode 100644 index 00000000000..6cf4670fe06 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.after_remove.json @@ -0,0 +1,11 @@ +{ + "action": "skip", + "changes": { + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.remove.json b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.remove.json new file mode 100644 index 00000000000..facc36861a1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.plan.remove.json @@ -0,0 +1,16 @@ +{ + "action": "update", + "changes": { + "default_endpoint_settings.pg_settings['lock_timeout']": { + "action": "update", + "old": "5000", + "remote": "5000" + }, + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.requests.remove.json b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.requests.remove.json new file mode 100644 index 00000000000..bfafc1054bc --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.requests.remove.json @@ -0,0 +1,19 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]", + "q": { + "update_mask": "spec.default_endpoint_settings.pg_settings" + }, + "body": { + "spec": { + "default_endpoint_settings": { + "pg_settings": { + "statement_timeout": "8000" + } + }, + "display_name": "Test Project for Default pg_settings Key Removal", + "history_retention_duration": "604800s", + "pg_version": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.test.toml b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/output.txt b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/output.txt new file mode 100644 index 00000000000..7b6866f1ad1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/output.txt @@ -0,0 +1,30 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-default-pg-settings-key-[UNIQUE_NAME]/default/files... +Created postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-project projects/test-pg-proj-[UNIQUE_NAME] +{ + "pg_settings": { + "lock_timeout": "5000", + "statement_timeout": "8000" + } +} + +=== Remove one of two default_endpoint_settings.pg_settings keys + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-default-pg-settings-key-[UNIQUE_NAME]/default + +Destroy: 1 deleted diff --git a/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/script b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/script new file mode 100644 index 00000000000..74a7974a679 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_default_pg_settings_key/script @@ -0,0 +1,28 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# default_endpoint_settings.pg_settings is a map: remove one of its two keys. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {pg_settings: .default_endpoint_settings.pg_settings}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {pg_settings: .default_endpoint_settings.pg_settings}' + +title "Remove one of two default_endpoint_settings.pg_settings keys" +update_file.py databricks.yml "$(printf ' lock_timeout: "5000"\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/databricks.yml.tmpl new file mode 100644 index 00000000000..97f53ddd7dd --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/databricks.yml.tmpl @@ -0,0 +1,14 @@ +bundle: + name: remove-enable-pg-native-login-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Native Login Removal" + pg_version: 16 + history_retention_duration: 604800s + enable_pg_native_login: true diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.deploy.remove.txt new file mode 100644 index 00000000000..b7645e47dfa --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.deploy.remove.txt @@ -0,0 +1,11 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-enable-pg-native-login-[UNIQUE_NAME]/default/files... +Error: cannot update resources.postgres_projects.my_project: updating id=projects/test-pg-proj-[UNIQUE_NAME]: Field 'spec.enable_pg_native_login' is in update_mask but not provided in request (400 INVALID_PARAMETER_VALUE) + +Endpoint: PATCH [DATABRICKS_URL]/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]?update_mask=spec.enable_pg_native_login +HTTP Status: 400 Bad Request +API error_code: INVALID_PARAMETER_VALUE +API message: Field 'spec.enable_pg_native_login' is in update_mask but not provided in request + +Files: 0 uploaded, 0 deleted + +Exit code: 1 diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.get.remove.json b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.get.remove.json new file mode 100644 index 00000000000..ea326122afd --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.get.remove.json @@ -0,0 +1,3 @@ +{ + "enable_pg_native_login": true +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.after_remove.json new file mode 100644 index 00000000000..1e8a7b747f3 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.after_remove.json @@ -0,0 +1,16 @@ +{ + "action": "update", + "changes": { + "enable_pg_native_login": { + "action": "update", + "old": true, + "remote": true + }, + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.remove.json b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.remove.json new file mode 100644 index 00000000000..1e8a7b747f3 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.plan.remove.json @@ -0,0 +1,16 @@ +{ + "action": "update", + "changes": { + "enable_pg_native_login": { + "action": "update", + "old": true, + "remote": true + }, + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.requests.remove.json b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.requests.remove.json new file mode 100644 index 00000000000..f70eb8d553a --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.requests.remove.json @@ -0,0 +1,14 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]", + "q": { + "update_mask": "spec.enable_pg_native_login" + }, + "body": { + "spec": { + "display_name": "Test Project for Native Login Removal", + "history_retention_duration": "604800s", + "pg_version": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.test.toml b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/output.txt b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/output.txt new file mode 100644 index 00000000000..8bef00f5f57 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/output.txt @@ -0,0 +1,27 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-enable-pg-native-login-[UNIQUE_NAME]/default/files... +Created postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-project projects/test-pg-proj-[UNIQUE_NAME] +{ + "enable_pg_native_login": true +} + +=== Remove enable_pg_native_login: true + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-enable-pg-native-login-[UNIQUE_NAME]/default + +Destroy: 1 deleted diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/script b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/script new file mode 100644 index 00000000000..5c6a3d4568d --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/script @@ -0,0 +1,28 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# enable_pg_native_login is a bool that defaults to false: remove it after setting it to true. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {enable_pg_native_login}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {enable_pg_native_login}' + +title "Remove enable_pg_native_login: true" +update_file.py databricks.yml "$(printf ' enable_pg_native_login: true\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/test.toml b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/test.toml new file mode 100644 index 00000000000..681240a26e0 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_enable_pg_native_login/test.toml @@ -0,0 +1,4 @@ +# Verified against a real workspace on 2026-11-19: the direct engine masks spec.enable_pg_native_login and omits it from +# the body, and the API rejects a masked scalar with no value. The old value stays in state, so +# out.plan.after_remove.json shows the removal pending again and every later deploy fails the same way. +Badness = "Removing enable_pg_native_login fails: the field is named in update_mask but omitted from the body, which the API rejects" diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_roles/remove_attribute/databricks.yml.tmpl new file mode 100644 index 00000000000..802a72b84bb --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/databricks.yml.tmpl @@ -0,0 +1,28 @@ +bundle: + name: remove-attribute-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Role Attribute Removal" + pg_version: 16 + history_retention_duration: 604800s + + postgres_branches: + main: + parent: ${resources.postgres_projects.my_project.id} + branch_id: main + no_expiry: true + + postgres_roles: + my_role: + parent: ${resources.postgres_branches.main.id} + role_id: test-role + postgres_role: app_role + attributes: + createdb: true + createrole: true diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.deploy.remove.txt new file mode 100644 index 00000000000..e03ecdb23ac --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.deploy.remove.txt @@ -0,0 +1,11 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-attribute-[UNIQUE_NAME]/default/files... +Error: cannot update resources.postgres_roles.my_role: updating id=projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role: Field 'spec.attributes.createdb' is in update_mask but not provided in request (400 INVALID_PARAMETER_VALUE) + +Endpoint: PATCH [DATABRICKS_URL]/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role?update_mask=spec.attributes.createdb +HTTP Status: 400 Bad Request +API error_code: INVALID_PARAMETER_VALUE +API message: Field 'spec.attributes.createdb' is in update_mask but not provided in request + +Files: 0 uploaded, 0 deleted + +Exit code: 1 diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/out.get.remove.json b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.get.remove.json new file mode 100644 index 00000000000..f2aa2eeb4c3 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.get.remove.json @@ -0,0 +1,7 @@ +{ + "attributes": { + "bypassrls": false, + "createdb": true, + "createrole": true + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.after_remove.json new file mode 100644 index 00000000000..e01e151165d --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.after_remove.json @@ -0,0 +1,16 @@ +{ + "action": "update", + "changes": { + "attributes.createdb": { + "action": "update", + "old": true, + "remote": true + }, + "postgres_role": { + "action": "skip", + "reason": "spec:input_only", + "old": "app_role", + "new": "app_role" + } + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.remove.json b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.remove.json new file mode 100644 index 00000000000..e01e151165d --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.plan.remove.json @@ -0,0 +1,16 @@ +{ + "action": "update", + "changes": { + "attributes.createdb": { + "action": "update", + "old": true, + "remote": true + }, + "postgres_role": { + "action": "skip", + "reason": "spec:input_only", + "old": "app_role", + "new": "app_role" + } + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/out.requests.remove.json b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.requests.remove.json new file mode 100644 index 00000000000..16a8571e1e0 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.requests.remove.json @@ -0,0 +1,15 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role", + "q": { + "update_mask": "spec.attributes.createdb" + }, + "body": { + "spec": { + "attributes": { + "createrole": true + }, + "postgres_role": "app_role" + } + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/out.test.toml b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/output.txt b/acceptance/bundle/resources/postgres_roles/remove_attribute/output.txt new file mode 100644 index 00000000000..8a94319b7fc --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/output.txt @@ -0,0 +1,39 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-attribute-[UNIQUE_NAME]/default/files... +Created postgres_branches.main +Created postgres_projects.my_project +Created postgres_roles.my_role +Files: 0 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-role projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role +{ + "attributes": { + "bypassrls": false, + "createdb": true, + "createrole": true + } +} + +=== Remove attributes.createdb: true, keeping createrole + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_branches.main + delete resources.postgres_projects.my_project + delete resources.postgres_roles.my_role + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase branches. +All data stored in them will be permanently lost: + delete resources.postgres_branches.main + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-attribute-[UNIQUE_NAME]/default + +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/script b/acceptance/bundle/resources/postgres_roles/remove_attribute/script new file mode 100644 index 00000000000..94d655f4855 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/script @@ -0,0 +1,28 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# attributes holds bools that default to false: remove createdb after setting it to true. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-role "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/roles/test-role" | jq '.status | {attributes}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-role "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/roles/test-role" | jq '.status | {attributes}' + +title "Remove attributes.createdb: true, keeping createrole" +update_file.py databricks.yml "$(printf ' createdb: true\n')" "" +step remove diff --git a/acceptance/bundle/resources/postgres_roles/remove_attribute/test.toml b/acceptance/bundle/resources/postgres_roles/remove_attribute/test.toml new file mode 100644 index 00000000000..35bc4860a12 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_attribute/test.toml @@ -0,0 +1,4 @@ +# Verified against a real workspace on 2026-11-19: the direct engine masks spec.attributes.createdb and omits it from +# the body, and the API rejects a masked scalar with no value. The old value stays in state, so +# out.plan.after_remove.json shows the removal pending again and every later deploy fails the same way. +Badness = "Removing attributes.createdb fails: the field is named in update_mask but omitted from the body, which the API rejects" diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/databricks.yml.tmpl b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/databricks.yml.tmpl new file mode 100644 index 00000000000..4c0f8da4435 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/databricks.yml.tmpl @@ -0,0 +1,27 @@ +bundle: + name: remove-membership-roles-$UNIQUE_NAME + +sync: + paths: [] + +resources: + postgres_projects: + my_project: + project_id: test-pg-proj-$UNIQUE_NAME + display_name: "Test Project for Role Membership Removal" + pg_version: 16 + history_retention_duration: 604800s + + postgres_branches: + main: + parent: ${resources.postgres_projects.my_project.id} + branch_id: main + no_expiry: true + + postgres_roles: + my_role: + parent: ${resources.postgres_branches.main.id} + role_id: test-role + postgres_role: app_role + membership_roles: + - DATABRICKS_SUPERUSER diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.deploy.remove.txt new file mode 100644 index 00000000000..d7c1692427a --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.deploy.remove.txt @@ -0,0 +1,4 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-membership-roles-[UNIQUE_NAME]/default/files... +Updated postgres_roles.my_role +Files: 0 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 2 unchanged diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.get.remove.json b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.get.remove.json new file mode 100644 index 00000000000..bf925b26236 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.get.remove.json @@ -0,0 +1,3 @@ +{ + "membership_roles": null +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.after_remove.json new file mode 100644 index 00000000000..84594a26765 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.after_remove.json @@ -0,0 +1,11 @@ +{ + "action": "skip", + "changes": { + "postgres_role": { + "action": "skip", + "reason": "spec:input_only", + "old": "app_role", + "new": "app_role" + } + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.remove.json b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.remove.json new file mode 100644 index 00000000000..b3cf9180e01 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.plan.remove.json @@ -0,0 +1,20 @@ +{ + "action": "update", + "changes": { + "membership_roles": { + "action": "update", + "old": [ + "DATABRICKS_SUPERUSER" + ], + "remote": [ + "DATABRICKS_SUPERUSER" + ] + }, + "postgres_role": { + "action": "skip", + "reason": "spec:input_only", + "old": "app_role", + "new": "app_role" + } + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.requests.remove.json b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.requests.remove.json new file mode 100644 index 00000000000..c7850b0604b --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.requests.remove.json @@ -0,0 +1,12 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role", + "q": { + "update_mask": "spec.membership_roles" + }, + "body": { + "spec": { + "postgres_role": "app_role" + } + } +} diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.test.toml b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/output.txt b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/output.txt new file mode 100644 index 00000000000..00a90ba85d5 --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/output.txt @@ -0,0 +1,37 @@ + +=== Initial deployment + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-membership-roles-[UNIQUE_NAME]/default/files... +Created postgres_branches.main +Created postgres_projects.my_project +Created postgres_roles.my_role +Files: 0 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] postgres get-role projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role +{ + "membership_roles": [ + "DATABRICKS_SUPERUSER" + ] +} + +=== Remove membership_roles + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.postgres_branches.main + delete resources.postgres_projects.my_project + delete resources.postgres_roles.my_role + +This action will result in the deletion of the following Lakebase projects along with +all their branches, databases, and endpoints. All data stored in them will be permanently lost: + delete resources.postgres_projects.my_project + +This action will result in the deletion of the following Lakebase branches. +All data stored in them will be permanently lost: + delete resources.postgres_branches.main + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-membership-roles-[UNIQUE_NAME]/default + +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/postgres_roles/remove_membership_roles/script b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/script new file mode 100644 index 00000000000..ce45c63ecbd --- /dev/null +++ b/acceptance/bundle/resources/postgres_roles/remove_membership_roles/script @@ -0,0 +1,28 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f "$OUT_REQUESTS" +} +trap cleanup EXIT + +# membership_roles is a repeated field: remove its only entry. +# Each step records whether the change reaches the backend: the planned changes, the +# deploy outcome, the PATCH it sent, the resource read back, and the plan that follows. +step() { + local name=$1 + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" | {action, changes}' > out.plan.$name.json + errcode $CLI bundle deploy &> out.deploy.$name.txt + print_requests.py --del-body project_id,branch_id,endpoint_id,role_id //postgres --method PATCH > out.requests.$name.json + $CLI postgres get-role "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/roles/test-role" | jq '.status | {membership_roles}' > out.get.$name.json + $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" | {action, changes}' > out.plan.after_$name.json +} + +title "Initial deployment" +trace $CLI bundle deploy +rm -f "$OUT_REQUESTS" +trace $CLI postgres get-role "projects/test-pg-proj-${UNIQUE_NAME}/branches/main/roles/test-role" | jq '.status | {membership_roles}' + +title "Remove membership_roles" +update_file.py databricks.yml "$(printf ' membership_roles:\n - DATABRICKS_SUPERUSER\n')" "" +step remove diff --git a/libs/testserver/postgres.go b/libs/testserver/postgres.go index 47bd4d02cb1..a57437e9df3 100644 --- a/libs/testserver/postgres.go +++ b/libs/testserver/postgres.go @@ -128,7 +128,8 @@ func (s *FakeWorkspace) PostgresProjectCreate(req Request, projectID string) Res DisplayName: project.Spec.DisplayName, PgVersion: project.Spec.PgVersion, HistoryRetentionDuration: historyRetention, - EnablePgNativeLogin: false, + EnablePgNativeLogin: project.Spec.EnablePgNativeLogin, + CustomTags: project.Spec.CustomTags, Owner: TestUser.UserName, BranchLogicalSizeLimitBytes: 8796093022208, // 8 TB (real API default) SyntheticStorageSizeBytes: 0, @@ -151,6 +152,7 @@ func (s *FakeWorkspace) PostgresProjectCreate(req Request, projectID string) Res if project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration != nil { project.Status.DefaultEndpointSettings.SuspendTimeoutDuration = project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration } + project.Status.DefaultEndpointSettings.PgSettings = project.Spec.DefaultEndpointSettings.PgSettings } project.Spec = echoedSpec[postgres.ProjectSpec](nil, req.Body, "", projectOneofGroups, projectInputOnlySpecFields...) } @@ -246,6 +248,21 @@ func (s *FakeWorkspace) PostgresProjectUpdate(req Request, name string) Response project.Status.DefaultEndpointSettings.SuspendTimeoutDuration = updateProject.Spec.DefaultEndpointSettings.SuspendTimeoutDuration } } + + mask := req.URL.Query().Get("update_mask") + body := requestBodyMap(req) + if maskApplies(mask, body, "spec.custom_tags") { + project.Status.CustomTags = updateProject.Spec.CustomTags + } + if maskApplies(mask, body, "spec.enable_pg_native_login") { + project.Status.EnablePgNativeLogin = updateProject.Spec.EnablePgNativeLogin + } + if maskApplies(mask, body, "spec.default_endpoint_settings.pg_settings") { + if project.Status.DefaultEndpointSettings == nil { + project.Status.DefaultEndpointSettings = &postgres.ProjectDefaultEndpointSettings{} + } + project.Status.DefaultEndpointSettings.PgSettings = updateProject.Spec.DefaultEndpointSettings.PgSettings + } } project.Spec = echoedSpec(project.Spec, req.Body, req.URL.Query().Get("update_mask"), projectOneofGroups, projectInputOnlySpecFields...) @@ -462,7 +479,11 @@ func (s *FakeWorkspace) PostgresBranchUpdate(req Request, name string) Response if branch.Status == nil { branch.Status = &postgres.BranchStatus{} } - branch.Status.IsProtected = updateBranch.Spec.IsProtected + // A mask covering is_protected with the field omitted keeps it: probed against a + // real workspace on 2026-11-19 with update_mask=spec. + if maskApplies(req.URL.Query().Get("update_mask"), requestBodyMap(req), "spec.is_protected") { + branch.Status.IsProtected = updateBranch.Spec.IsProtected + } if updateBranch.Spec.ExpireTime != nil { branch.Status.ExpireTime = updateBranch.Spec.ExpireTime } @@ -676,6 +697,9 @@ func (s *FakeWorkspace) PostgresEndpointCreate(req Request, parent, endpointID s endpoint.Status.SuspendTimeoutDuration = endpoint.Spec.SuspendTimeoutDuration } endpoint.Status.Disabled = endpoint.Spec.Disabled + if endpoint.Spec.Settings != nil { + endpoint.Status.Settings = endpoint.Spec.Settings + } } endpoint.Spec = echoedSpec[postgres.EndpointSpec](nil, req.Body, "", endpointOneofGroups) @@ -878,6 +902,41 @@ func parentPath(path string) string { return before } +// Repeated fields under spec. Unlike a scalar, one named in update_mask but absent from +// the body is accepted and cleared: probed against a real workspace on 2026-11-19, +// update_mask=spec.custom_tags with no custom_tags removes every tag, and the same holds +// for spec.membership_roles. +var postgresRepeatedMaskPaths = []string{"spec.custom_tags", "spec.membership_roles"} + +// Map fields under spec. One named in update_mask but absent from the body is accepted +// and keeps the stored map (probed against a real workspace on 2026-11-19). +var postgresMapMaskPaths = []string{"spec.default_endpoint_settings.pg_settings", "spec.settings.pg_settings"} + +// maskApplies reports whether an update writes path: the mask covers it (names it, an +// enclosing message, or the whole spec) and the body carries it, or the mask names a +// repeated field the body omits, which clears it. +func maskApplies(mask string, body map[string]any, path string) bool { + for entry := range strings.SplitSeq(mask, ",") { + entry = strings.TrimSpace(entry) + if entry != path && !strings.HasPrefix(path, entry+".") { + continue + } + if bodyHasPath(body, strings.Split(path, ".")) { + return true + } + if entry == path && slices.Contains(postgresRepeatedMaskPaths, path) { + return true + } + } + return false +} + +func requestBodyMap(req Request) map[string]any { + var body map[string]any + _ = json.Unmarshal(req.Body, &body) + return body +} + // missingMaskedField returns the first update_mask path the API would reject // because the mask names it but the request body carries no value for it, which is // how a removal from bundle config reaches the API. Verified against a real @@ -899,6 +958,9 @@ func missingMaskedField(req Request, oneofGroups map[string][]string) string { // unpopulatedOneofGroup checks. continue } + if slices.Contains(postgresRepeatedMaskPaths, path) || slices.Contains(postgresMapMaskPaths, path) { + continue + } parts := strings.Split(path, ".") if path == "" || path == "*" || len(parts) < 2 { // A whole message the request omits is tolerated: the Terraform provider @@ -1057,7 +1119,15 @@ func (s *FakeWorkspace) PostgresEndpointUpdate(req Request, name string) Respons if updateEndpoint.Spec.SuspendTimeoutDuration != nil { endpoint.Status.SuspendTimeoutDuration = updateEndpoint.Spec.SuspendTimeoutDuration } - endpoint.Status.Disabled = updateEndpoint.Spec.Disabled + mask, body := req.URL.Query().Get("update_mask"), requestBodyMap(req) + // A mask covering disabled with the field omitted keeps it: probed against a real + // workspace on 2026-11-19 with update_mask=spec. + if maskApplies(mask, body, "spec.disabled") { + endpoint.Status.Disabled = updateEndpoint.Spec.Disabled + } + if maskApplies(mask, body, "spec.settings.pg_settings") { + endpoint.Status.Settings = &postgres.EndpointSettings{PgSettings: updateEndpoint.Spec.Settings.PgSettings} + } } endpoint.Spec = echoedSpec(endpoint.Spec, req.Body, req.URL.Query().Get("update_mask"), endpointOneofGroups) @@ -1834,6 +1904,10 @@ func (s *FakeWorkspace) PostgresRoleList(parent string) Response { // desired spec. An empty update_mask updates all fields, matching the API // ("if unspecified, all fields will be updated when possible"). func (s *FakeWorkspace) PostgresRoleUpdate(req Request, name string) Response { + if path := missingMaskedField(req, nil); path != "" { + return missingMaskedFieldResponse(path) + } + defer s.LockUnlock()() role, exists := s.PostgresRoles[name] @@ -1861,7 +1935,7 @@ func (s *FakeWorkspace) PostgresRoleUpdate(req Request, name string) Response { if mask := req.URL.Query().Get("update_mask"); mask != "" { paths = strings.Split(mask, ",") } - role.Status = applyRoleSpecMask(role.Status, roleStatusFromSpec(updateRole.Spec), paths) + role.Status = applyRoleSpecMask(role.Status, roleStatusFromSpec(updateRole.Spec), paths, requestBodyMap(req)) role.Status.RoleId = roleID } @@ -1875,26 +1949,40 @@ func (s *FakeWorkspace) PostgresRoleUpdate(req Request, name string) Response { } // applyRoleSpecMask applies the fields named in paths (the update_mask) from -// desired onto existing. Paths are relative to the Role and "spec."-prefixed; the -// bare path "spec" replaces the whole subtree, and an empty paths slice replaces -// everything. +// desired onto existing. Paths are relative to the Role and "spec."-prefixed, and an +// empty paths slice replaces everything. // -// A nested path such as "spec.attributes.createdb" is collapsed to its top-level -// field ("attributes"), and that whole field is taken from desired. This is a -// simplification: the real backend masks at the individual leaf (verified on -// dogfood 2026-06-16 — update_mask=spec.attributes.createdb leaves the sibling -// attributes untouched), but the direct engine always sends the full spec in the -// request body, so the collapsed result is identical for the requests it makes. -func applyRoleSpecMask(existing, desired *postgres.RoleRoleStatus, paths []string) *postgres.RoleRoleStatus { +// The bare path "spec" is a patch, as probed against a real workspace on 2026-11-19: +// it applies the attributes the body carries, keeps an omitted one, and clears an +// omitted membership_roles. A path under attributes applies that one attribute; the +// real backend masks at the leaf (verified on dogfood 2026-06-16 — +// update_mask=spec.attributes.createdb leaves the sibling attributes untouched). +func applyRoleSpecMask(existing, desired *postgres.RoleRoleStatus, paths []string, body map[string]any) *postgres.RoleRoleStatus { if len(paths) == 0 || existing == nil { return desired } - result := *existing + var expanded []string for _, p := range paths { - field, _, _ := strings.Cut(strings.TrimPrefix(p, "spec."), ".") - switch field { - case "spec": - result = *desired + if p != "spec" { + expanded = append(expanded, p) + continue + } + expanded = append(expanded, "spec.membership_roles") + // postgres_role, auth_method and identity_type are immutable, and the backend + // silently ignores them under the whole-spec mask. + for _, field := range []string{"attributes.bypassrls", "attributes.createdb", "attributes.createrole"} { + if bodyHasPath(body, strings.Split("spec."+field, ".")) { + expanded = append(expanded, "spec."+field) + } + } + } + result := *existing + attrs := postgres.RoleAttributes{ForceSendFields: []string{"Bypassrls", "Createdb", "Createrole"}} + if existing.Attributes != nil { + attrs.Bypassrls, attrs.Createdb, attrs.Createrole = existing.Attributes.Bypassrls, existing.Attributes.Createdb, existing.Attributes.Createrole + } + for _, p := range expanded { + switch strings.TrimPrefix(p, "spec.") { case "postgres_role": result.PostgresRole = desired.PostgresRole case "auth_method": @@ -1904,9 +1992,16 @@ func applyRoleSpecMask(existing, desired *postgres.RoleRoleStatus, paths []strin case "membership_roles": result.MembershipRoles = desired.MembershipRoles case "attributes": - result.Attributes = desired.Attributes + attrs = *desired.Attributes + case "attributes.bypassrls": + attrs.Bypassrls = desired.Attributes.Bypassrls + case "attributes.createdb": + attrs.Createdb = desired.Attributes.Createdb + case "attributes.createrole": + attrs.Createrole = desired.Attributes.Createrole } } + result.Attributes = &attrs return &result } diff --git a/libs/testserver/postgres_spec.go b/libs/testserver/postgres_spec.go index f55a2952085..7000bfcdad5 100644 --- a/libs/testserver/postgres_spec.go +++ b/libs/testserver/postgres_spec.go @@ -10,7 +10,8 @@ import ( // update. Since 2026-11-12 the API returns spec as stored for projects, branches, // endpoints, databases and roles (catalogs, data APIs and synced tables were not // observed to change and still return status only): the fields the -// caller set (a field masked but absent from the body keeps its previous value), +// caller set (a field masked but absent from the body keeps its previous value, except +// a repeated field, which is cleared), // minus inputOnly fields that are consulted once and never echoed. Defaults the // backend materializes appear only in status, not in spec. // @@ -63,6 +64,8 @@ func echoedSpec[T any](stored *T, body []byte, mask string, oneofGroups map[stri parts := strings.Split(rel, ".") if v, ok := specMapGet(bodySpec, parts); ok { specMapSet(result, parts, v) + } else if slices.Contains(postgresRepeatedMaskPaths, path) { + specMapDelete(result, parts) } } } From 486c1715e6522273eb8f84aa6383059346fd149f Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 19 Nov 2026 14:03:16 +0000 Subject: [PATCH 2/2] acc: fix remove_custom_tags removing the wrong tag first Co-authored-by: Isaac --- .../remove_custom_tags/out.deploy.remove.txt | 4 +++ .../remove_custom_tags/out.get.remove.json | 3 +++ .../remove_custom_tags/out.get.shrink.json | 4 +-- .../out.plan.after_remove.json | 11 ++++++++ .../remove_custom_tags/out.plan.remove.json | 26 +++++++++++++++++++ .../remove_custom_tags/out.plan.shrink.json | 4 +-- .../out.requests.remove.json | 14 ++++++++++ .../out.requests.shrink.json | 4 +-- .../remove_custom_tags/output.txt | 21 --------------- .../remove_custom_tags/script | 4 +-- 10 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.remove.txt create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.remove.json create mode 100644 acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.remove.json diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.remove.txt b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.remove.txt new file mode 100644 index 00000000000..a283a1a7622 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.deploy.remove.txt @@ -0,0 +1,4 @@ +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/remove-custom-tags-[UNIQUE_NAME]/default/files... +Updated postgres_projects.my_project +Files: 0 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.remove.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.remove.json new file mode 100644 index 00000000000..71f02695d0c --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.remove.json @@ -0,0 +1,3 @@ +{ + "custom_tags": null +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json index d00028e7eba..32a8bb67c36 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.get.shrink.json @@ -1,8 +1,8 @@ { "custom_tags": [ { - "key": "team", - "value": "data" + "key": "env", + "value": "test" } ] } diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_remove.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_remove.json new file mode 100644 index 00000000000..6cf4670fe06 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.after_remove.json @@ -0,0 +1,11 @@ +{ + "action": "skip", + "changes": { + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.remove.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.remove.json new file mode 100644 index 00000000000..665f9f409d7 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.remove.json @@ -0,0 +1,26 @@ +{ + "action": "update", + "changes": { + "custom_tags": { + "action": "update", + "old": [ + { + "key": "env", + "value": "test" + } + ], + "remote": [ + { + "key": "env", + "value": "test" + } + ] + }, + "pg_version": { + "action": "skip", + "reason": "spec:input_only", + "old": 16, + "new": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json index 3f34994c75c..e1593d853e5 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.plan.shrink.json @@ -15,8 +15,8 @@ ], "new": [ { - "key": "team", - "value": "data" + "key": "env", + "value": "test" } ], "remote": [ diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.remove.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.remove.json new file mode 100644 index 00000000000..0ca1a6b41c2 --- /dev/null +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.remove.json @@ -0,0 +1,14 @@ +{ + "method": "PATCH", + "path": "/api/2.0/postgres/projects/test-pg-proj-[UNIQUE_NAME]", + "q": { + "update_mask": "spec.custom_tags" + }, + "body": { + "spec": { + "display_name": "Test Project for Custom Tags Removal", + "history_retention_duration": "604800s", + "pg_version": 16 + } + } +} diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json index 88834ab339b..d5f97053816 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/out.requests.shrink.json @@ -8,8 +8,8 @@ "spec": { "custom_tags": [ { - "key": "team", - "value": "data" + "key": "env", + "value": "test" } ], "display_name": "Test Project for Custom Tags Removal", diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt index e9defa22496..5591c0e5aad 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/output.txt @@ -24,25 +24,6 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged === Remove one of two custom_tags === Remove the last custom_tag, leaving no custom_tags in the config -old=' custom_tags:\n - key: team\n value: data' not found in filename='databricks.yml' -bundle: - name: remove-custom-tags-[UNIQUE_NAME] - -sync: - paths: [] - -resources: - postgres_projects: - my_project: - project_id: test-pg-proj-[UNIQUE_NAME] - display_name: "Test Project for Custom Tags Removal" - pg_version: 16 - history_retention_duration: 604800s - custom_tags: - - - key: team - value: data - >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: @@ -55,5 +36,3 @@ all their branches, databases, and endpoints. All data stored in them will be pe All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/remove-custom-tags-[UNIQUE_NAME]/default Destroy: 1 deleted - -Exit code: 1 diff --git a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script index 388a7697892..4649b10a97e 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script +++ b/acceptance/bundle/resources/postgres_projects/remove_custom_tags/script @@ -24,9 +24,9 @@ rm -f "$OUT_REQUESTS" trace $CLI postgres get-project "projects/test-pg-proj-${UNIQUE_NAME}" | jq '.status | {custom_tags}' title "Remove one of two custom_tags" -update_file.py databricks.yml "$(printf ' - key: env\n value: test\n')" "" +update_file.py databricks.yml "$(printf ' - key: team\n value: data\n')" "" step shrink title "Remove the last custom_tag, leaving no custom_tags in the config" -update_file.py databricks.yml "$(printf ' custom_tags:\n - key: team\n value: data\n')" "" +update_file.py databricks.yml "$(printf ' custom_tags:\n - key: env\n value: test\n')" "" step remove