Skip to content

Commit 62e8da3

Browse files
authored
Add UCX history schema and table for storing UCX's artifact (#2744)
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes Add UCX history schema and table for storing UCX's artifact. The artifacts are, amongst other things, going to be used for migration progress tracking. ### Linked issues Resolves #2572 ### Functionality - [x] modified existing command: `databricks labs ucx create-ucx-catalog` ### Tests - [ ] manually tested - [x] added unit tests - [x] added integration tests
1 parent 77e0b6d commit 62e8da3

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/databricks/labs/ucx/progress/install.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
import logging
2+
from dataclasses import dataclass
23

34
from databricks.labs.lsql.backends import SqlBackend
45
from databricks.labs.lsql.deployment import SchemaDeployer
6+
7+
from databricks.labs.ucx.__about__ import __version__
58
from databricks.labs.ucx.progress.workflow_runs import WorkflowRun
69

10+
711
logger = logging.getLogger(__name__)
812

913

14+
@dataclass(frozen=True, kw_only=True)
15+
class Historical:
16+
workspace_id: int
17+
"""The identifier of the workspace where this historical record was generated."""
18+
19+
job_run_id: int
20+
"""The identifier of the job run that generated this historical record."""
21+
22+
object_type: str
23+
"""The inventory table for which this historical record was generated."""
24+
25+
object_id: list[str]
26+
"""The type-specific identifier for the corresponding inventory record."""
27+
28+
data: dict[str, str]
29+
"""Type-specific JSON-encoded data of the inventory record."""
30+
31+
failures: list[str]
32+
"""The list of problems associated with the object that this inventory record covers."""
33+
34+
owner: str
35+
"""The identity that has ownership of the object."""
36+
37+
ucx_version: str = __version__
38+
"""The UCX semantic version."""
39+
40+
1041
class ProgressTrackingInstallation:
1142
"""Install resources for UCX's progress tracking."""
1243

@@ -19,4 +50,5 @@ def __init__(self, sql_backend: SqlBackend, ucx_catalog: str) -> None:
1950
def run(self) -> None:
2051
self._schema_deployer.deploy_schema()
2152
self._schema_deployer.deploy_table("workflow_runs", WorkflowRun)
53+
self._schema_deployer.deploy_table("historical", Historical)
2254
logger.info("Installation completed successfully!")
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
def test_progress_tracking_installer_creates_workflow_runs_table(az_cli_ctx) -> None:
1+
import pytest
2+
3+
4+
@pytest.mark.parametrize("table_name", ["workflow_runs", "historical"])
5+
def test_progress_tracking_installer_creates_table(az_cli_ctx, table_name) -> None:
26
az_cli_ctx.progress_tracking_installation.run()
37
query = (
48
f"SELECT 1 FROM tables WHERE table_catalog = '{az_cli_ctx.config.ucx_catalog}' "
5-
"AND table_schema = 'multiworkspace' AND table_name = 'workflow_runs'"
9+
f"AND table_schema = 'multiworkspace' AND table_name = '{table_name}'"
610
)
711
assert any(az_cli_ctx.sql_backend.fetch(query, catalog="system", schema="information_schema"))

tests/unit/progress/test_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def test_progress_tracking_installation_run_creates_progress_tracking_schema(moc
77
assert "CREATE SCHEMA IF NOT EXISTS ucx.multiworkspace" in mock_backend.queries[0]
88

99

10-
def test_progress_tracking_installation_run_creates_workflow_runs_table(mock_backend) -> None:
10+
def test_progress_tracking_installation_run_creates_tables(mock_backend) -> None:
1111
installation = ProgressTrackingInstallation(mock_backend, "ucx")
1212
installation.run()
1313
# Dataclass to schema conversion is tested within the lsql package
14-
assert any("CREATE TABLE IF NOT EXISTS" in query for query in mock_backend.queries)
14+
assert sum("CREATE TABLE IF NOT EXISTS" in query for query in mock_backend.queries) == 2

0 commit comments

Comments
 (0)