Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0d11ce2
direct: check the internal id before updating or deleting what is at …
denik Nov 25, 2026
46b40dc
direct: fail a delete whose identity cannot be checked, warn about th…
denik Nov 25, 2026
310d6e4
direct: delete a child under its parent's found name; warn only when …
denik Nov 25, 2026
50ee46a
direct: list a child of a deleted, moved parent by its ID under the p…
denik Nov 25, 2026
5807484
Add the PR link to the changelog fragment
denik Nov 26, 2026
8db1a28
direct: set every field of the schema and volume list requests (exhau…
denik Nov 26, 2026
addc8e0
direct: never send an unverified child delete; find moved parents by …
denik Nov 26, 2026
718edeb
direct: order a with_parent child after its parent; follow moved pare…
denik Nov 26, 2026
d3c60aa
direct: test fixes for the 403 search and staticcheck
denik Nov 26, 2026
0003d74
direct: re-target only unverified UC children under a moved parent
denik Nov 26, 2026
51d86e4
direct: a with_parent child keeps only its edge to its parent
denik Nov 26, 2026
4d0a3bb
acc: drop a trailing space in prevent_destroy_mixed_case_schema
denik Nov 26, 2026
7b284f5
direct: limit the moved-parent lookup to UC children; order and selec…
denik Nov 26, 2026
d9feb5a
direct: check a with_parent entry's parent against the whole selectio…
denik Nov 26, 2026
8c8cc5e
direct: list every unverified child of a deleted moved parent with it
denik Nov 27, 2026
b7a7d52
direct: narrow to the identity check; the destroy lookup and moved pa…
denik Nov 27, 2026
c27c39c
direct: separate advice for deploy and delete when another object is …
denik Nov 27, 2026
48f5e2d
acc: cover a config that names the renamed schema or volume
denik Nov 28, 2026
53426c4
acc: drop the cloud-specific storage_location from the volume plan entry
denik Nov 28, 2026
3b5e0bc
acc: show destroy leaving another object at the recorded name alone
denik Nov 29, 2026
d69a66d
direct: delete warning says a renamed copy is left behind; plainer ch…
denik Nov 29, 2026
efce9ca
acc: use || true for cleanup in the new tests, errcode is gone
denik Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/schema-volume-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* The direct deployment engine no longer updates or deletes a schema or volume at the bundle's recorded name when its `schema_id` or `volume_id` differs from the recorded one: `bundle deploy` plans a create instead, and `bundle destroy` only drops the bundle's entry from the state, with a warning. A schema or volume deleted and created again outside the bundle is therefore no longer taken for the bundle's: deploy fails on its name until it is bound again with `bundle deployment unbind` and `bundle deployment bind`. ([#8056](https://github.com/databricks/cli/pull/8056))
9 changes: 6 additions & 3 deletions acceptance/bin/replay_tfstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ def main():
continue
for nf in NAME_FIELDS:
if attrs.get(nf):
name_to_attrs[str(attrs[nf])] = attrs
# Keyed lowercased: UC lowercases names (a schema created as MySchema is stored as
# myschema), so the tfstate may hold the lowercased form of the name the create
# request sent.
name_to_attrs[str(attrs[nf]).lower()] = attrs

id_map = {}
for req in requests:
Expand All @@ -149,10 +152,10 @@ def main():
# map its recorded id to the freshly minted one.
create_name = None
if isinstance(body, dict):
create_name = next((str(body[nf]) for nf in NAME_FIELDS if body.get(nf)), None)
create_name = next((str(body[nf]).lower() for nf in NAME_FIELDS if body.get(nf)), None)
if req["method"] == "POST" and create_name in name_to_attrs:
attrs = name_to_attrs[create_name]
if str(attrs["id"]) != create_name:
if str(attrs["id"]).lower() != create_name:
# Backend-minted primary id (jobs, pipelines, volumes): map recorded -> minted.
new_id = next((str(resp[f]) for f in ID_FIELDS if f in resp), None)
if new_id is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
schemas:
schema1:
catalog_name: main
name: test-schema-$UNIQUE_NAME
comment: c1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = true
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

=== Deploy a schema

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Created schemas.schema1
Files: 2 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

=== Out of band, rename the schema away, and create another one under its name

>>> [CLI] schemas update main.test-schema-[UNIQUE_NAME] --new-name test-schema-moved-[UNIQUE_NAME]
{
"full_name": "main.test-schema-moved-[UNIQUE_NAME]",
"schema_id": "[SCHEMA_ID]"
}

=== Destroy sends no delete for the other schema: it warns and only drops the bundle's entry from the state

>>> [CLI] bundle destroy --auto-approve
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so no delete is sent for it, and its entry is dropped from the deployment state. If the bundle's was renamed outside the bundle, it is left in place under its new name: delete it outside the bundle. If this object is the bundle's (deleted and created again outside the bundle), delete it outside the bundle.

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default

Destroy: 0 deleted

>>> print_requests.py //unity-catalog

>>> [CLI] bundle summary --output json
{
"id": null,
"modified_status": "created"
}

=== The other schema is left alone

>>> [CLI] schemas get main.test-schema-[UNIQUE_NAME]
{
"full_name": "main.test-schema-[UNIQUE_NAME]",
"schema_id": "[FOREIGN_SCHEMA_ID]"
}

=== The bundle's renamed schema is left behind

>>> [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME]
{
"full_name": "main.test-schema-moved-[UNIQUE_NAME]",
"schema_id": "[SCHEMA_ID]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
envsubst < databricks.yml.tmpl > databricks.yml

SCHEMA="main.test-schema-${UNIQUE_NAME}"
MOVED_SCHEMA="main.test-schema-moved-${UNIQUE_NAME}"

cleanup() {
# Whatever destroy left behind.
$CLI schemas delete "$MOVED_SCHEMA" --force > LOG.cleanup 2>&1 || true
$CLI schemas delete "$SCHEMA" --force >> LOG.cleanup 2>&1 || true

# Consume the cleanup's requests so none are left recorded.
print_requests.py //unity-catalog &> LOG.cleanup_requests
}
trap cleanup EXIT

title "Deploy a schema"
trace $CLI bundle deploy
print_requests.py //unity-catalog &> LOG.deploy_requests
add_repl "$($CLI schemas get "$SCHEMA" | jq -r .schema_id)" SCHEMA_ID

title "Out of band, rename the schema away, and create another one under its name"
trace $CLI schemas update "$SCHEMA" --new-name "test-schema-moved-${UNIQUE_NAME}" | schema_fields
add_repl "$($CLI schemas create "test-schema-${UNIQUE_NAME}" main | jq -r .schema_id)" FOREIGN_SCHEMA_ID
print_requests.py //unity-catalog &> LOG.oob_requests

# The config still names the schema at its old name.
title "Destroy sends no delete for the other schema: it warns and only drops the bundle's entry from the state"
trace $CLI bundle destroy --auto-approve
trace print_requests.py //unity-catalog
trace $CLI bundle summary --output json | jq '.resources.schemas.schema1 | {id, modified_status}'

title "The other schema is left alone"
trace $CLI schemas get "$SCHEMA" | schema_fields

title "The bundle's renamed schema is left behind"
trace $CLI schemas get "$MOVED_SCHEMA" | schema_fields
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Badness = "Destroy does not look for the bundle's schema after a rename out of band: it drops the state entry and leaves the renamed schema behind. It should find it by its schema_id."
Cloud = true

Ignore = [
".databricks",
".gitignore",
"databricks.yml",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
schemas:
schema1:
catalog_name: main
name: test-schema-moved-$UNIQUE_NAME
comment: c1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Created schemas.schema1
Files: 2 uploaded, 0 deleted
Files: 3 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

=== Out of band, rename the schema away, and create another one under its name
Expand All @@ -15,47 +15,108 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
"schema_id": "[SCHEMA_ID]"
}

=== The plan takes the other schema for the bundle's, though its schema_id differs, and plans to update it
=== The other schema has another schema_id, so the plan does not take it for the bundle's: it plans a create

>>> [CLI] bundle plan --output json
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.

{
"resources.schemas.schema1": {
"action": "update",
"new_state": {
"value": {
"catalog_name": "main",
"comment": "c1",
"name": "test-schema-[UNIQUE_NAME]"
}
},
"remote_state": {
"browse_only": false,
"action": "create",
"new_state": {
"value": {
"catalog_name": "main",
"catalog_type": "MANAGED_CATALOG",
"created_by": "[USERNAME]",
"enable_predictive_optimization": "INHERIT",
"full_name": "main.test-schema-[UNIQUE_NAME]",
"name": "test-schema-[UNIQUE_NAME]",
"owner": "[USERNAME]",
"schema_id": "[FOREIGN_SCHEMA_ID]"
"comment": "c1",
"name": "test-schema-[UNIQUE_NAME]"
}
},
"changes": {
"schema_id": {
"action": "skip",
"reason": "internal_id",
"old": "[SCHEMA_ID]"
}
}
}

=== Deploy leaves the other schema alone: the create fails on its name

>>> musterr [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again.

Error: cannot create resources.schemas.schema1: Schema 'test-schema-[UNIQUE_NAME]' already exists (400 SCHEMA_ALREADY_EXISTS)

Endpoint: POST [DATABRICKS_URL]/api/2.1/unity-catalog/schemas
HTTP Status: 400 Bad Request
API error_code: SCHEMA_ALREADY_EXISTS
API message: Schema 'test-schema-[UNIQUE_NAME]' already exists

Files: 2 uploaded, 0 deleted

>>> print_requests.py //unity-catalog
{
"method": "POST",
"path": "/api/2.1/unity-catalog/schemas",
"body": {
"catalog_name": "main",
"comment": "c1",
"name": "test-schema-[UNIQUE_NAME]"
}
}

=== Point the config at the bundle's renamed schema: the plan finds it there by its schema_id

>>> [CLI] bundle plan --output json
{
"id": "main.test-schema-moved-[UNIQUE_NAME]",
"action": "update_id",
"state_only": true,
"new_state": {
"value": {
"catalog_name": "main",
"comment": "c1",
"name": "test-schema-moved-[UNIQUE_NAME]"
}
},
"changes": {
"name": {
"action": "skip",
"reason": "remote_already_set",
"old": "test-schema-[UNIQUE_NAME]",
"new": "test-schema-moved-[UNIQUE_NAME]",
"remote": "test-schema-moved-[UNIQUE_NAME]"
},
"changes": {
"comment": {
"action": "update",
"old": "c1",
"new": "c1"
},
"schema_id": {
"action": "skip",
"reason": "internal_id",
"old": "[SCHEMA_ID]",
"remote": "[FOREIGN_SCHEMA_ID]"
}
"schema_id": {
"action": "skip",
"reason": "internal_id",
"old": "[SCHEMA_ID]",
"remote": "[SCHEMA_ID]"
}
}
}

=== Destroy deletes the other schema
=== Deploy takes the renamed schema for the bundle's, and sends nothing to the other one

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
Files: 1 uploaded, 0 deleted
Resources: 0 created, 0 changed, 0 deleted, 1 unchanged

>>> print_requests.py //unity-catalog

>>> [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME]
{
"full_name": "main.test-schema-moved-[UNIQUE_NAME]",
"schema_id": "[SCHEMA_ID]"
}

>>> [CLI] schemas get main.test-schema-[UNIQUE_NAME]
{
"full_name": "main.test-schema-[UNIQUE_NAME]",
"schema_id": "[FOREIGN_SCHEMA_ID]"
}

=== Destroy deletes the bundle's schema at its new name, not the other one

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
Expand All @@ -71,19 +132,19 @@ Destroy: 1 deleted
>>> print_requests.py //unity-catalog
{
"method": "DELETE",
"path": "/api/2.1/unity-catalog/schemas/main.test-schema-[UNIQUE_NAME]",
"path": "/api/2.1/unity-catalog/schemas/main.test-schema-moved-[UNIQUE_NAME]",
"q": {
"force": "true"
}
}

>>> musterr [CLI] schemas get main.test-schema-[UNIQUE_NAME]
Error: Schema 'main.test-schema-[UNIQUE_NAME]' does not exist.
>>> musterr [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME]
Error: Schema 'main.test-schema-moved-[UNIQUE_NAME]' does not exist.

=== The bundle's own schema is left behind
=== The other schema is left alone

>>> [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME]
>>> [CLI] schemas get main.test-schema-[UNIQUE_NAME]
{
"full_name": "main.test-schema-moved-[UNIQUE_NAME]",
"schema_id": "[SCHEMA_ID]"
"full_name": "main.test-schema-[UNIQUE_NAME]",
"schema_id": "[FOREIGN_SCHEMA_ID]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,38 @@ cleanup() {
}
trap cleanup EXIT

# Drop the remote_state fields that differ between clouds or from the test server.
plan() {
trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id effective_predictive_optimization_flag storage_location
}

title "Deploy a schema"
trace $CLI bundle deploy
print_requests.py //unity-catalog &> LOG.deploy_requests
add_repl "$($CLI schemas get "$SCHEMA" | jq -r .schema_id)" SCHEMA_ID

title "Out of band, rename the schema away, and create another one under its name"
trace $CLI schemas update "$SCHEMA" --new-name "test-schema-moved-${UNIQUE_NAME}" | jq '{full_name, schema_id}'
trace $CLI schemas update "$SCHEMA" --new-name "test-schema-moved-${UNIQUE_NAME}" | schema_fields
add_repl "$($CLI schemas create "test-schema-${UNIQUE_NAME}" main | jq -r .schema_id)" FOREIGN_SCHEMA_ID
print_requests.py //unity-catalog &> LOG.oob_requests

title "The plan takes the other schema for the bundle's, though its schema_id differs, and plans to update it"
plan
title "The other schema has another schema_id, so the plan does not take it for the bundle's: it plans a create"
trace $CLI bundle plan --output json | plan_filter.py resources.schemas.schema1

title "Deploy leaves the other schema alone: the create fails on its name"
trace musterr $CLI bundle deploy
trace print_requests.py //unity-catalog

title "Point the config at the bundle's renamed schema: the plan finds it there by its schema_id"
envsubst < databricks-moved.yml.tmpl > databricks.yml
trace $CLI bundle plan --output json | plan_filter.py resources.schemas.schema1

title "Deploy takes the renamed schema for the bundle's, and sends nothing to the other one"
trace $CLI bundle deploy
trace print_requests.py //unity-catalog
trace $CLI schemas get "$MOVED_SCHEMA" | schema_fields
trace $CLI schemas get "$SCHEMA" | schema_fields

title "Destroy deletes the other schema"
title "Destroy deletes the bundle's schema at its new name, not the other one"
trace $CLI bundle destroy --auto-approve
trace print_requests.py //unity-catalog
trace musterr $CLI schemas get "$SCHEMA"
trace musterr $CLI schemas get "$MOVED_SCHEMA"

title "The bundle's own schema is left behind"
trace $CLI schemas get "$MOVED_SCHEMA" | jq '{full_name, schema_id}'
title "The other schema is left alone"
trace $CLI schemas get "$SCHEMA" | schema_fields
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Badness = "The plan reads the recorded name and takes whatever schema is there without checking schema_id: a schema someone else created at that name after ours was renamed is planned as an update and then deleted by destroy, while ours is left behind. A schema_id mismatch should mean the bundle's schema is not there, and the plan should look for it by its schema_id."
Cloud = true

Ignore = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
schemas:
schema1:
catalog_name: main
name: test-schema-$UNIQUE_NAME
comment: c1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = true
EnvMatrix.DMS = ["", "true"]
Loading
Loading