Skip to content

Commit 8015fc5

Browse files
denikIsaac
andcommitted
direct: destroy finds a schema or volume renamed out of band, and the resources in it
Restores what was narrowed out of #8056: DoFindByInternalID (schemas, volumes) with the testserver list routes, findInMovedParents, the with_parent plan field and its makeGraph and --select handling, Destroy at a moved ID, and their tests. Adds its own changelog fragment (schema-moved-parent.md); #8056's fragment is unchanged. Removes the Badness notes of destroy_after_rename_out_of_band and foreign_at_recorded_name. aws: TestAccept/bundle/resources/schemas/foreign_at_recorded_name TestAccept/bundle/resources/schemas/destroy_after_rename_out_of_band TestAccept/bundle/resources/schemas/recreated_at_recorded_name TestAccept/bundle/resources/schemas/destroy_renamed_with_model_and_secret TestAccept/bundle/resources/volumes/foreign_at_recorded_name TestAccept/bundle/resources/volumes/prevent_destroy_in_renamed_schema TestAccept/bundle/resources/volumes/removed_from_renamed_schema TestAccept/bundle/resources/volumes/prevent_destroy_schema_without_dependency TestAccept/bundle/resources/volumes/prevent_destroy_mixed_case_schema TestAccept/bundle/resources/volumes/select_renamed_schema TestAccept/bundle/resources/registered_models/prevent_destroy_in_renamed_schema TestAccept/bundle/resources/registered_models/removed_from_renamed_schema Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 30938bb commit 8015fc5

103 files changed

Lines changed: 2308 additions & 135 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Fixed `bundle destroy` in the direct deployment engine leaving behind a schema or volume renamed out of band: it now finds it by its `schema_id` or `volume_id` and deletes it at its new name. A deploy that removes such a schema or volume from the config deletes it there too (a schema with its contents); before, it only dropped it from the state. The resources in a renamed schema are deleted at their new name, or listed as going with the schema's delete, so approval and `lifecycle.prevent_destroy` still apply to them. ([#8096](https://github.com/databricks/cli/pull/8096))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
schemas:
6+
schema1:
7+
catalog_name: main
8+
name: test-schema-$UNIQUE_NAME
9+
registered_models:
10+
model1:
11+
catalog_name: main
12+
schema_name: ${resources.schemas.schema1.name}
13+
name: mymodel
14+
lifecycle:
15+
prevent_destroy: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cloud = true
2+
EnvMatrix.DMS = ["", "true"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
=== Deploy a schema with a registered model in it that must not be destroyed
3+
4+
>>> [CLI] bundle deploy
5+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
6+
Created registered_models.model1
7+
Created schemas.schema1
8+
Files: 2 uploaded, 0 deleted
9+
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
10+
11+
=== Rename the schema and the model out of band
12+
13+
>>> [CLI] schemas update main.test-schema-[UNIQUE_NAME] --new-name test-schema-renamed-[UNIQUE_NAME]
14+
{
15+
"full_name": "main.test-schema-renamed-[UNIQUE_NAME]",
16+
"schema_id": "[UUID]"
17+
}
18+
19+
>>> [CLI] registered-models update main.test-schema-renamed-[UNIQUE_NAME].mymodel --new-name mymodel2
20+
{
21+
"full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel2"
22+
}
23+
24+
=== The model has no internal ID and is not at its new path, but the schema's delete would take it, so destroy lists it and prevent_destroy stops it
25+
26+
>>> musterr [CLI] bundle destroy --auto-approve
27+
Error: resources.registered_models.model1 has lifecycle.prevent_destroy set, but the plan calls for this resource to be recreated or destroyed. To avoid this error, disable lifecycle.prevent_destroy for resources.registered_models.model1
28+
29+
30+
>>> print_requests.py //unity-catalog
31+
32+
>>> [CLI] registered-models get main.test-schema-renamed-[UNIQUE_NAME].mymodel2
33+
{
34+
"full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel2"
35+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
OLD_SCHEMA="main.test-schema-${UNIQUE_NAME}"
4+
NEW_SCHEMA="main.test-schema-renamed-${UNIQUE_NAME}"
5+
6+
cleanup() {
7+
errcode $CLI schemas delete "$NEW_SCHEMA" --force > LOG.cleanup 2>&1
8+
errcode $CLI schemas delete "$OLD_SCHEMA" --force >> LOG.cleanup 2>&1
9+
10+
# Consume the destroy's requests so none are left recorded.
11+
print_requests.py //unity-catalog &> LOG.destroy_requests
12+
}
13+
trap cleanup EXIT
14+
15+
title "Deploy a schema with a registered model in it that must not be destroyed"
16+
trace $CLI bundle deploy
17+
print_requests.py //unity-catalog &> LOG.deploy_requests
18+
19+
title "Rename the schema and the model out of band"
20+
trace $CLI schemas update "$OLD_SCHEMA" --new-name "test-schema-renamed-${UNIQUE_NAME}" | schema_fields
21+
trace $CLI registered-models update "$NEW_SCHEMA.mymodel" --new-name mymodel2 | registered_model_fields
22+
print_requests.py //unity-catalog &> LOG.rename_requests
23+
24+
title "The model has no internal ID and is not at its new path, but the schema's delete would take it, so destroy lists it and prevent_destroy stops it"
25+
trace musterr $CLI bundle destroy --auto-approve
26+
trace print_requests.py //unity-catalog
27+
trace $CLI registered-models get "$NEW_SCHEMA.mymodel2" | registered_model_fields
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Cloud = true
2+
3+
Ignore = [
4+
".databricks",
5+
".gitignore",
6+
"databricks.yml",
7+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
schemas:
6+
schema1:
7+
catalog_name: main
8+
name: test-schema-renamed-$UNIQUE_NAME
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
schemas:
6+
schema1:
7+
catalog_name: main
8+
name: test-schema-$UNIQUE_NAME
9+
registered_models:
10+
model1:
11+
catalog_name: main
12+
schema_name: ${resources.schemas.schema1.name}
13+
name: mymodel
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cloud = true
2+
EnvMatrix.DMS = ["", "true"]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
=== Deploy a schema with a registered model in it, and rename the schema out of band
3+
4+
>>> [CLI] bundle deploy
5+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
6+
Created registered_models.model1
7+
Created schemas.schema1
8+
Files: 3 uploaded, 0 deleted
9+
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
10+
11+
>>> [CLI] schemas update main.test-schema-[UNIQUE_NAME] --new-name test-schema-renamed-[UNIQUE_NAME]
12+
{
13+
"full_name": "main.test-schema-renamed-[UNIQUE_NAME]",
14+
"schema_id": "[UUID]"
15+
}
16+
17+
=== Follow the rename in the config and remove the model from it: the model has no internal ID, but is found at its new path inside the bundle's schema
18+
19+
>>> [CLI] bundle plan
20+
delete registered_models.model1
21+
22+
Plan: 0 to add, 0 to change, 1 to delete, 1 unchanged
23+
24+
=== Deploy deletes the model at its new path, and keeps the schema
25+
26+
>>> [CLI] bundle deploy --auto-approve
27+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
28+
Deleted registered_models.model1
29+
Files: 2 uploaded, 0 deleted
30+
Resources: 0 created, 0 changed, 1 deleted, 1 unchanged
31+
32+
>>> print_requests.py //unity-catalog
33+
{
34+
"method": "DELETE",
35+
"path": "/api/2.1/unity-catalog/models/main.test-schema-renamed-[UNIQUE_NAME].mymodel"
36+
}
37+
38+
>>> musterr [CLI] registered-models get main.test-schema-renamed-[UNIQUE_NAME].mymodel
39+
Error: Routine or Model 'main.test-schema-renamed-[UNIQUE_NAME].mymodel' does not exist.
40+
41+
>>> [CLI] schemas get main.test-schema-renamed-[UNIQUE_NAME]
42+
{
43+
"full_name": "main.test-schema-renamed-[UNIQUE_NAME]",
44+
"schema_id": "[UUID]"
45+
}
46+
47+
>>> [CLI] bundle destroy --auto-approve
48+
The following resources will be deleted:
49+
delete resources.schemas.schema1
50+
51+
This action will result in the deletion of the following UC schemas. Any underlying data may be lost:
52+
delete resources.schemas.schema1
53+
54+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
55+
56+
Destroy: 1 deleted

0 commit comments

Comments
 (0)