Skip to content

Commit cce5b94

Browse files
committed
bundle migrate: remove new top-level command, keep deployment migrate
The new approach (BuildStateFromTF, no API calls) has been folded into the existing 'bundle deployment migrate' command. The separate 'bundle migrate' command is removed — it was redundant. Also add resolve_test.go: verify that int and bool cross-resource references work correctly when Method B returns a string value. structaccess.Set already handles string→int and string→bool conversion via strconv, so no bug exists. Co-authored-by: Isaac
1 parent 1c7832c commit cce5b94

3 files changed

Lines changed: 78 additions & 193 deletions

File tree

bundle/migrate/resolve_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package migrate_test
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/databricks/cli/bundle/migrate"
8+
"github.com/databricks/cli/libs/structs/structaccess"
9+
"github.com/databricks/cli/libs/structs/structpath"
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
// state with src job having int and bool fields set.
15+
func testState() migrate.TFStateAttrs {
16+
return migrate.TFStateAttrs{
17+
"databricks_job": {
18+
"src": json.RawMessage(`{
19+
"id": "111",
20+
"max_concurrent_runs": 4,
21+
"always_running": true
22+
}`),
23+
"dst": json.RawMessage(`{
24+
"id": "222",
25+
"max_concurrent_runs": 4,
26+
"always_running": true
27+
}`),
28+
},
29+
}
30+
}
31+
32+
// TestResolveFieldRefInt proves that when Method B (template evaluation) wins for
33+
// an int field, the returned string value is still usable: structaccess.Set must
34+
// parse it back to int and not error.
35+
func TestResolveFieldRefInt(t *testing.T) {
36+
state := testState()
37+
// Remove dst from state so Method A fails and Method B must be used.
38+
delete(state["databricks_job"], "dst")
39+
40+
ctx := t.Context()
41+
fieldPath, err := structpath.ParsePath("max_concurrent_runs")
42+
require.NoError(t, err)
43+
44+
value, err := migrate.ResolveFieldRef(ctx, state, "jobs", "dst", fieldPath,
45+
"${resources.jobs.src.max_concurrent_runs}")
46+
require.NoError(t, err)
47+
48+
// Method B succeeds: returns string "4". Verify Set converts it to int.
49+
type target struct {
50+
MaxConcurrentRuns int `json:"max_concurrent_runs"`
51+
}
52+
s := &target{}
53+
err = structaccess.Set(s, fieldPath, value)
54+
assert.NoError(t, err, "Set should parse string %q into int field", value)
55+
assert.Equal(t, 4, s.MaxConcurrentRuns)
56+
}
57+
58+
// TestResolveFieldRefBool is the same for a bool field.
59+
func TestResolveFieldRefBool(t *testing.T) {
60+
state := testState()
61+
delete(state["databricks_job"], "dst")
62+
63+
ctx := t.Context()
64+
fieldPath, err := structpath.ParsePath("always_running")
65+
require.NoError(t, err)
66+
67+
value, err := migrate.ResolveFieldRef(ctx, state, "jobs", "dst", fieldPath,
68+
"${resources.jobs.src.always_running}")
69+
require.NoError(t, err)
70+
71+
type target struct {
72+
AlwaysRunning bool `json:"always_running"`
73+
}
74+
s := &target{}
75+
err = structaccess.Set(s, fieldPath, value)
76+
assert.NoError(t, err, "Set should parse string %q into bool field", value)
77+
assert.Equal(t, true, s.AlwaysRunning)
78+
}

cmd/bundle/bundle.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.htm
3838
cmd.AddCommand(newDebugCommand())
3939
cmd.AddCommand(newOpenCommand())
4040
cmd.AddCommand(newPlanCommand())
41-
cmd.AddCommand(newMigrateCommand())
4241
cmd.AddCommand(newConfigRemoteSyncCommand())
4342

4443
// Bundle Metadata Service (DMS) read-only command groups. Only `get`

cmd/bundle/migrate.go

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

0 commit comments

Comments
 (0)