diff --git a/src/databricks/labs/ucx/progress/install.py b/src/databricks/labs/ucx/progress/install.py index 5f2ab69f7e..bbb7388c60 100644 --- a/src/databricks/labs/ucx/progress/install.py +++ b/src/databricks/labs/ucx/progress/install.py @@ -1,12 +1,43 @@ import logging +from dataclasses import dataclass from databricks.labs.lsql.backends import SqlBackend from databricks.labs.lsql.deployment import SchemaDeployer + +from databricks.labs.ucx.__about__ import __version__ from databricks.labs.ucx.progress.workflow_runs import WorkflowRun + logger = logging.getLogger(__name__) +@dataclass(frozen=True, kw_only=True) +class Historical: + workspace_id: int + """The identifier of the workspace where this historical record was generated.""" + + job_run_id: int + """The identifier of the job run that generated this historical record.""" + + object_type: str + """The inventory table for which this historical record was generated.""" + + object_id: list[str] + """The type-specific identifier for the corresponding inventory record.""" + + data: dict[str, str] + """Type-specific JSON-encoded data of the inventory record.""" + + failures: list[str] + """The list of problems associated with the object that this inventory record covers.""" + + owner: str + """The identity that has ownership of the object.""" + + ucx_version: str = __version__ + """The UCX semantic version.""" + + class ProgressTrackingInstallation: """Install resources for UCX's progress tracking.""" @@ -19,4 +50,5 @@ def __init__(self, sql_backend: SqlBackend, ucx_catalog: str) -> None: def run(self) -> None: self._schema_deployer.deploy_schema() self._schema_deployer.deploy_table("workflow_runs", WorkflowRun) + self._schema_deployer.deploy_table("historical", Historical) logger.info("Installation completed successfully!") diff --git a/tests/integration/progress/test_install.py b/tests/integration/progress/test_install.py index 02f77d82b2..1e49fdbd18 100644 --- a/tests/integration/progress/test_install.py +++ b/tests/integration/progress/test_install.py @@ -1,7 +1,11 @@ -def test_progress_tracking_installer_creates_workflow_runs_table(az_cli_ctx) -> None: +import pytest + + +@pytest.mark.parametrize("table_name", ["workflow_runs", "historical"]) +def test_progress_tracking_installer_creates_table(az_cli_ctx, table_name) -> None: az_cli_ctx.progress_tracking_installation.run() query = ( f"SELECT 1 FROM tables WHERE table_catalog = '{az_cli_ctx.config.ucx_catalog}' " - "AND table_schema = 'multiworkspace' AND table_name = 'workflow_runs'" + f"AND table_schema = 'multiworkspace' AND table_name = '{table_name}'" ) assert any(az_cli_ctx.sql_backend.fetch(query, catalog="system", schema="information_schema")) diff --git a/tests/unit/progress/test_install.py b/tests/unit/progress/test_install.py index d7013c316c..2bb63bbf03 100644 --- a/tests/unit/progress/test_install.py +++ b/tests/unit/progress/test_install.py @@ -7,8 +7,8 @@ def test_progress_tracking_installation_run_creates_progress_tracking_schema(moc assert "CREATE SCHEMA IF NOT EXISTS ucx.multiworkspace" in mock_backend.queries[0] -def test_progress_tracking_installation_run_creates_workflow_runs_table(mock_backend) -> None: +def test_progress_tracking_installation_run_creates_tables(mock_backend) -> None: installation = ProgressTrackingInstallation(mock_backend, "ucx") installation.run() # Dataclass to schema conversion is tested within the lsql package - assert any("CREATE TABLE IF NOT EXISTS" in query for query in mock_backend.queries) + assert sum("CREATE TABLE IF NOT EXISTS" in query for query in mock_backend.queries) == 2