Skip to content

Add UCX history schema and table for storing UCX's artifact #2744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/databricks/labs/ucx/progress/install.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand All @@ -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!")
8 changes: 6 additions & 2 deletions tests/integration/progress/test_install.py
Original file line number Diff line number Diff line change
@@ -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"))
4 changes: 2 additions & 2 deletions tests/unit/progress/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading