Skip to content

Commit 06061ae

Browse files
authored
bundle/dms: record deployment_mode on the deployment version (#5445)
## Changes Record the bundle target deployment mode on each DMS version. Adds a `deployment_mode` field (and the `DEPLOYMENT_MODE_DEVELOPMENT` / `DEPLOYMENT_MODE_PRODUCTION` enum) to `tmpdms.Version`, and sets it in the `CreateVersion` request from `bundle.mode`. Not set on the deployment: `Deployment.deployment_mode` is derived server-side from the most recent version's mode (output-only), so the CLI only sets it on the version. A target with no `mode` maps to an empty value, which is omitted (the server treats it as unspecified) — we don't fabricate a default. ## Why The SDK's `bundle.Version` already carries `deployment_mode` ("captured at the time of this version"), but the CLI never populated it, so every version recorded a null mode. This stamps it so each version records whether it was a development or production deployment. ## Tests Added a unit test for the mode mapping (development / production / unset). The `bundle/dms` acceptance outputs are unchanged because those targets don't set a mode. Verified live against a workspace: a `mode: development` target now records `deployment_mode: DEPLOYMENT_MODE_DEVELOPMENT` on the created version. This pull request and its description were written by Isaac, an AI coding agent.
1 parent 53109f9 commit 06061ae

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

bundle/deploy/lock/deployment_metadata_service.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/databricks/cli/bundle"
17+
"github.com/databricks/cli/bundle/config"
1718
"github.com/databricks/cli/bundle/deploy"
1819
"github.com/databricks/cli/bundle/deployplan"
1920
"github.com/databricks/cli/bundle/statemgmt"
@@ -153,10 +154,11 @@ func acquireLock(ctx context.Context, b *bundle.Bundle, svc *tmpdms.DeploymentMe
153154
Parent: "deployments/" + deploymentID,
154155
VersionID: versionID,
155156
Version: &tmpdms.Version{
156-
DisplayName: b.Config.Bundle.Name,
157-
CliVersion: build.GetInfo().Version,
158-
VersionType: versionType,
159-
TargetName: b.Config.Bundle.Target,
157+
DisplayName: b.Config.Bundle.Name,
158+
DeploymentMode: deploymentMode(b.Config.Bundle.Mode),
159+
CliVersion: build.GetInfo().Version,
160+
VersionType: versionType,
161+
TargetName: b.Config.Bundle.Target,
160162
// Same git provenance the CLI records in metadata.json.
161163
GitInfo: &tmpdms.GitInfo{
162164
OriginURL: b.Config.Bundle.Git.OriginURL,
@@ -342,3 +344,16 @@ func isAborted(err error) bool {
342344
apiErr, ok := errors.AsType[*apierr.APIError](err)
343345
return ok && apiErr.StatusCode == http.StatusConflict && apiErr.ErrorCode == "ABORTED"
344346
}
347+
348+
// deploymentMode maps a bundle target mode to the DMS deployment mode enum.
349+
// Unset target modes produce an empty value, which is omitted from the request.
350+
func deploymentMode(mode config.Mode) tmpdms.DeploymentMode {
351+
switch mode {
352+
case config.Development:
353+
return tmpdms.DeploymentModeDevelopment
354+
case config.Production:
355+
return tmpdms.DeploymentModeProduction
356+
default:
357+
return ""
358+
}
359+
}

bundle/deploy/lock/deployment_metadata_service_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lock
33
import (
44
"testing"
55

6+
"github.com/databricks/cli/bundle/config"
67
"github.com/databricks/cli/bundle/deployplan"
78
"github.com/databricks/cli/libs/tmpdms"
89
"github.com/stretchr/testify/assert"
@@ -52,3 +53,21 @@ func TestGoalToVersionType(t *testing.T) {
5253
_, ok = goalToVersionType(GoalUnbind)
5354
assert.False(t, ok)
5455
}
56+
57+
func TestDeploymentMode(t *testing.T) {
58+
tests := []struct {
59+
mode config.Mode
60+
expected tmpdms.DeploymentMode
61+
}{
62+
{config.Development, tmpdms.DeploymentModeDevelopment},
63+
{config.Production, tmpdms.DeploymentModeProduction},
64+
{"", ""},
65+
{"unknown", ""},
66+
}
67+
68+
for _, tt := range tests {
69+
t.Run(string(tt.mode), func(t *testing.T) {
70+
assert.Equal(t, tt.expected, deploymentMode(tt.mode))
71+
})
72+
}
73+
}

libs/tmpdms/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type (
1717
OperationStatus string
1818
OperationActionType string
1919
DeploymentResourceType string
20+
DeploymentMode string
2021
)
2122

2223
const (
@@ -47,6 +48,11 @@ const (
4748
VersionTypeDestroy VersionType = "VERSION_TYPE_DESTROY"
4849
)
4950

51+
const (
52+
DeploymentModeDevelopment DeploymentMode = "DEPLOYMENT_MODE_DEVELOPMENT"
53+
DeploymentModeProduction DeploymentMode = "DEPLOYMENT_MODE_PRODUCTION"
54+
)
55+
5056
const (
5157
OperationStatusUnspecified OperationStatus = "OPERATION_STATUS_UNSPECIFIED"
5258
OperationStatusSucceeded OperationStatus = "OPERATION_STATUS_SUCCEEDED"
@@ -119,6 +125,7 @@ type Version struct {
119125
VersionType VersionType `json:"version_type,omitempty"`
120126
CompletionReason VersionComplete `json:"completion_reason,omitempty"`
121127
CompletedBy string `json:"completed_by,omitempty"`
128+
DeploymentMode DeploymentMode `json:"deployment_mode,omitempty"`
122129
DisplayName string `json:"display_name,omitempty"`
123130
TargetName string `json:"target_name,omitempty"`
124131
GitInfo *GitInfo `json:"git_info,omitempty"`

0 commit comments

Comments
 (0)