diff --git a/bundle/deploy/lock/deployment_metadata_service.go b/bundle/deploy/lock/deployment_metadata_service.go index a831b87746..5206a852ee 100644 --- a/bundle/deploy/lock/deployment_metadata_service.go +++ b/bundle/deploy/lock/deployment_metadata_service.go @@ -14,6 +14,7 @@ import ( "time" "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/deploy" "github.com/databricks/cli/bundle/deployplan" "github.com/databricks/cli/bundle/statemgmt" @@ -153,10 +154,11 @@ func acquireLock(ctx context.Context, b *bundle.Bundle, svc *tmpdms.DeploymentMe Parent: "deployments/" + deploymentID, VersionID: versionID, Version: &tmpdms.Version{ - DisplayName: b.Config.Bundle.Name, - CliVersion: build.GetInfo().Version, - VersionType: versionType, - TargetName: b.Config.Bundle.Target, + DisplayName: b.Config.Bundle.Name, + DeploymentMode: deploymentMode(b.Config.Bundle.Mode), + CliVersion: build.GetInfo().Version, + VersionType: versionType, + TargetName: b.Config.Bundle.Target, // Same git provenance the CLI records in metadata.json. GitInfo: &tmpdms.GitInfo{ OriginURL: b.Config.Bundle.Git.OriginURL, @@ -342,3 +344,16 @@ func isAborted(err error) bool { apiErr, ok := errors.AsType[*apierr.APIError](err) return ok && apiErr.StatusCode == http.StatusConflict && apiErr.ErrorCode == "ABORTED" } + +// deploymentMode maps a bundle target mode to the DMS deployment mode enum. +// Unset target modes produce an empty value, which is omitted from the request. +func deploymentMode(mode config.Mode) tmpdms.DeploymentMode { + switch mode { + case config.Development: + return tmpdms.DeploymentModeDevelopment + case config.Production: + return tmpdms.DeploymentModeProduction + default: + return "" + } +} diff --git a/bundle/deploy/lock/deployment_metadata_service_test.go b/bundle/deploy/lock/deployment_metadata_service_test.go index 980cce0093..4217a47c69 100644 --- a/bundle/deploy/lock/deployment_metadata_service_test.go +++ b/bundle/deploy/lock/deployment_metadata_service_test.go @@ -3,6 +3,7 @@ package lock import ( "testing" + "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/deployplan" "github.com/databricks/cli/libs/tmpdms" "github.com/stretchr/testify/assert" @@ -52,3 +53,21 @@ func TestGoalToVersionType(t *testing.T) { _, ok = goalToVersionType(GoalUnbind) assert.False(t, ok) } + +func TestDeploymentMode(t *testing.T) { + tests := []struct { + mode config.Mode + expected tmpdms.DeploymentMode + }{ + {config.Development, tmpdms.DeploymentModeDevelopment}, + {config.Production, tmpdms.DeploymentModeProduction}, + {"", ""}, + {"unknown", ""}, + } + + for _, tt := range tests { + t.Run(string(tt.mode), func(t *testing.T) { + assert.Equal(t, tt.expected, deploymentMode(tt.mode)) + }) + } +} diff --git a/libs/tmpdms/types.go b/libs/tmpdms/types.go index 1729876ec8..9e4f900c6f 100644 --- a/libs/tmpdms/types.go +++ b/libs/tmpdms/types.go @@ -17,6 +17,7 @@ type ( OperationStatus string OperationActionType string DeploymentResourceType string + DeploymentMode string ) const ( @@ -47,6 +48,11 @@ const ( VersionTypeDestroy VersionType = "VERSION_TYPE_DESTROY" ) +const ( + DeploymentModeDevelopment DeploymentMode = "DEPLOYMENT_MODE_DEVELOPMENT" + DeploymentModeProduction DeploymentMode = "DEPLOYMENT_MODE_PRODUCTION" +) + const ( OperationStatusUnspecified OperationStatus = "OPERATION_STATUS_UNSPECIFIED" OperationStatusSucceeded OperationStatus = "OPERATION_STATUS_SUCCEEDED" @@ -119,6 +125,7 @@ type Version struct { VersionType VersionType `json:"version_type,omitempty"` CompletionReason VersionComplete `json:"completion_reason,omitempty"` CompletedBy string `json:"completed_by,omitempty"` + DeploymentMode DeploymentMode `json:"deployment_mode,omitempty"` DisplayName string `json:"display_name,omitempty"` TargetName string `json:"target_name,omitempty"` GitInfo *GitInfo `json:"git_info,omitempty"`