Skip to content

Commit 125ccfa

Browse files
authored
Added ability to run create-table-mapping command as collection (#2602)
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes This PR enables create-table-mapping command to run as a collection. ### Linked issues <!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> #1782 ### Functionality - [ ] modified existing command: `databricks labs ucx ...` ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] added unit tests - [ ] verified on staging environment (screenshot attached) https://github.com/user-attachments/assets/a6d5cfe2-05ea-4fd9-b035-bde87aace32a
1 parent df7f1d7 commit 125ccfa

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

labs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ commands:
6565

6666
- name: create-table-mapping
6767
description: create initial table mapping for review
68+
flags:
69+
- name: run-as-collection
70+
description: (Optional) boolean flag to indicate to run the cmd as a collection. Default is False.
6871

6972
- name: ensure-assessment-run
7073
description: ensure the assessment job was run on a workspace

src/databricks/labs/ucx/cli.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,21 @@ def manual_workspace_info(w: WorkspaceClient, prompts: Prompts):
153153

154154

155155
@ucx.command
156-
def create_table_mapping(w: WorkspaceClient):
156+
def create_table_mapping(
157+
w: WorkspaceClient,
158+
ctx: WorkspaceContext | None = None,
159+
run_as_collection: bool = False,
160+
a: AccountClient | None = None,
161+
):
157162
"""create initial table mapping for review"""
158-
ctx = WorkspaceContext(w)
159-
path = ctx.table_mapping.save(ctx.tables_crawler, ctx.workspace_info)
160-
webbrowser.open(f"{w.config.host}/#workspace{path}")
163+
workspace_contexts = _get_workspace_contexts(w, a, run_as_collection)
164+
if ctx:
165+
workspace_contexts = [ctx]
166+
for workspace_ctx in workspace_contexts:
167+
logger.info(f"Running cmd for workspace {workspace_ctx.workspace_client.get_workspace_id()}")
168+
path = workspace_ctx.table_mapping.save(workspace_ctx.tables_crawler, workspace_ctx.workspace_info)
169+
if len(workspace_contexts) == 1:
170+
webbrowser.open(f"{w.config.host}/#workspace{path}")
161171

162172

163173
@ucx.command

tests/unit/test_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ def test_manual_workspace_info(ws):
265265
manual_workspace_info(ws, prompts)
266266

267267

268-
def test_create_table_mapping(ws):
268+
def test_create_table_mapping(ws, acc_client):
269+
ctx = WorkspaceContext(ws)
269270
with pytest.raises(ValueError, match='databricks labs ucx sync-workspace-info'):
270-
create_table_mapping(ws)
271+
create_table_mapping(ws, ctx, False, acc_client)
271272

272273

273274
def test_validate_external_locations(ws):

0 commit comments

Comments
 (0)