Skip to content

Commit 6770dfa

Browse files
Allow bind and unbind with deployment history shadow enabled
1 parent ffda837 commit 6770dfa

12 files changed

Lines changed: 94 additions & 50 deletions

File tree

‎acceptance/bundle/dms/bind-unbind-unsupported/output.txt‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎acceptance/bundle/dms/bind-unbind-unsupported/script‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎acceptance/bundle/dms/bind-unbind-unsupported/test.toml‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

acceptance/bundle/dms/bind-unbind-unsupported/databricks.yml.tmpl renamed to acceptance/bundle/dms/bind-unbind/databricks.yml.tmpl

File renamed without changes.
File renamed without changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
=== Bind an existing job with deployment history enabled
3+
>>> [CLI] bundle deployment bind foo [JOB_ID] --auto-approve
4+
Successfully bound job with an id '[JOB_ID]'
5+
Run 'bundle deploy' to deploy changes to your workspace
6+
7+
=== Deploy keeps the bound job ID and enables shadow history
8+
>>> [CLI] bundle deploy
9+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-bind-unbind-[UNIQUE_NAME]/default/files...
10+
Updated jobs.foo
11+
Files: 2 uploaded, 0 deleted
12+
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
13+
14+
>>> jq {features, resource_id: .state["resources.jobs.foo"].__id__} .databricks/bundle/default/resources.json
15+
{
16+
"features": {
17+
"deployment_history_shadow": {}
18+
},
19+
"resource_id": "[JOB_ID]"
20+
}
21+
22+
=== Unbind preserves the shadow history marker and leaves the job intact
23+
>>> [CLI] bundle deployment unbind foo
24+
25+
>>> jq {features, state} .databricks/bundle/default/resources.json
26+
{
27+
"features": {
28+
"deployment_history_shadow": {}
29+
},
30+
"state": {}
31+
}
32+
33+
>>> [CLI] jobs get [JOB_ID]
34+
{
35+
"job_id": [JOB_ID]
36+
}
37+
38+
=== Rebind preserves the existing shadow history marker
39+
>>> [CLI] bundle deployment bind foo [JOB_ID] --auto-approve
40+
Successfully bound job with an id '[JOB_ID]'
41+
Run 'bundle deploy' to deploy changes to your workspace
42+
43+
>>> jq {features, resource_id: .state["resources.jobs.foo"].__id__} .databricks/bundle/default/resources.json
44+
{
45+
"features": {
46+
"deployment_history_shadow": {}
47+
},
48+
"resource_id": "[JOB_ID]"
49+
}
50+
51+
=== A subsequent deploy continues managing the same job
52+
>>> [CLI] bundle deploy
53+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-bind-unbind-[UNIQUE_NAME]/default/files...
54+
Files: 0 uploaded, 0 deleted
55+
Resources: 0 created, 0 changed, 0 deleted, 1 unchanged
56+
57+
>>> jq {features, resource_id: .state["resources.jobs.foo"].__id__} .databricks/bundle/default/resources.json
58+
{
59+
"features": {
60+
"deployment_history_shadow": {}
61+
},
62+
"resource_id": "[JOB_ID]"
63+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
title "Bind an existing job with deployment history enabled"
4+
job_id=$($CLI jobs create --json '{"name": "bind-target-'$UNIQUE_NAME'"}' | jq -r '.job_id')
5+
add_repl "$job_id" JOB_ID
6+
trace $CLI bundle deployment bind foo "$job_id" --auto-approve
7+
8+
title "Deploy keeps the bound job ID and enables shadow history"
9+
trace $CLI bundle deploy
10+
trace jq '{features, resource_id: .state["resources.jobs.foo"].__id__}' .databricks/bundle/default/resources.json
11+
12+
title "Unbind preserves the shadow history marker and leaves the job intact"
13+
trace $CLI bundle deployment unbind foo
14+
trace jq '{features, state}' .databricks/bundle/default/resources.json
15+
trace $CLI jobs get "$job_id" | jq '{job_id}'
16+
17+
title "Rebind preserves the existing shadow history marker"
18+
trace $CLI bundle deployment bind foo "$job_id" --auto-approve
19+
trace jq '{features, resource_id: .state["resources.jobs.foo"].__id__}' .databricks/bundle/default/resources.json
20+
21+
title "A subsequent deploy continues managing the same job"
22+
trace $CLI bundle deploy
23+
trace jq '{features, resource_id: .state["resources.jobs.foo"].__id__}' .databricks/bundle/default/resources.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RecordRequests = false
2+
# Verify shadow history markers and resource IDs across bind, deploy, unbind, and rebind.
3+
Cloud = false

‎bundle/direct/bind.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ type BindResult struct {
6363
// Call Finalize to commit the state or Cancel to discard.
6464
func (b *DeploymentBundle) Bind(ctx context.Context, client *databricks.WorkspaceClient, configRoot *config.Root, statePath, resourceKey, resourceID string) (*BindResult, error) {
6565
// Check if the resource is already managed (bound to a different ID)
66-
// The state is opened without a DMS client, so the writes below record nothing;
67-
// phases.Bind and phases.Unbind refuse to run at all when recording is enabled.
66+
// Bind imports file state without creating a deployment history version.
6867
var checkStateDB dstate.DeploymentState
6968
if err := checkStateDB.Open(ctx, statePath, dstate.ReadingFile, dstate.WithRecovery(true), dstate.OpenDmsArgs{}); err != nil {
7069
// State that cannot be read is not the same as state without a binding:

‎bundle/direct/dstate/state.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,6 @@ func (db *DeploymentState) setupWal() error {
961961
walHead.Features = make(map[string]struct{})
962962
}
963963
walHead.Features[FeatureDeploymentHistoryShadow] = struct{}{}
964-
case WritingFile:
965-
walHead.Features = map[string]struct{}{}
966964
default:
967965
// Other modes preserve the existing markers.
968966
}

0 commit comments

Comments
 (0)